Skip to content

Commit

Permalink
🔃 [EngCom] Public Pull Requests - 2.2-develop
Browse files Browse the repository at this point in the history
Accepted Public Pull Requests:
 - #21699: [Backport] 20484 - Fix performance leak in salesrule collection (by @david-fuehr)
 - #21528: [Backport] Fix empty cart validation (by @wojtekn)
 - #21695: [Backport] 19276 - Fixed price renderer issue (by @mage2pratik)
 - #21694: [Backport] Setting default sorting #21493 (by @mage2pratik)
 - #21691: [Backport][Admin] Made configurable product variations table cell label hidden (by @eduard13)
 - #19098: 2.2.6 Use batches and direct queries to fix sales address upgrade (by @rikwillems)


Fixed GitHub Issues:
 - #19117: High Database Load for Sales Rule Validation (reported by @rauberdaniel) has been fixed in #21699 by @david-fuehr in 2.2-develop branch
   Related commits:
     1. 9a839d1
     2. 8e7ddbf
     3. a3e87bd
     4. bfd1d4f
     5. 571cf9b
     6. ea34b66
     7. dbf6714

 - #21294: Cart can't be emptied if any product is out of stock (reported by @wojtekn) has been fixed in #21528 by @wojtekn in 2.2-develop branch
   Related commits:
     1. 7bb5dd4
     2. 847115e
     3. 42b03bb

 - #19276: Change different product price on selecting different product swatches on category pages (reported by @ankurverma5540) has been fixed in #21695 by @mage2pratik in 2.2-develop branch
   Related commits:
     1. a4a4878

 - #21493: Setting default sorting (reported by @iproger) has been fixed in #21694 by @mage2pratik in 2.2-develop branch
   Related commits:
     1. b4283aa

 - #20527: [Admin] Configurable product variations table cell labels wrong position (reported by @vasilii-b) has been fixed in #21691 by @eduard13 in 2.2-develop branch
   Related commits:
     1. adf4425
  • Loading branch information
magento-engcom-team authored Mar 14, 2019
2 parents a089cfe + eb1ead3 commit 30ed829
Show file tree
Hide file tree
Showing 8 changed files with 219 additions and 140 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@
method="post"
id="form-validate"
data-mage-init='{"Magento_Checkout/js/action/update-shopping-cart":
{"validationURL" : "/checkout/cart/updateItemQty"}
{"validationURL" : "/checkout/cart/updateItemQty",
"updateCartActionContainer": "#update_cart_action_container"}
}'
class="form form-cart">
<?= $block->getBlockHtml('formkey') ?>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ define([
$.widget('mage.updateShoppingCart', {
options: {
validationURL: '',
eventName: 'updateCartItemQty'
eventName: 'updateCartItemQty',
updateCartActionContainer: ''
},

/** @inheritdoc */
Expand All @@ -31,7 +32,9 @@ define([
* @return {Boolean}
*/
onSubmit: function (event) {
if (!this.options.validationURL) {
var action = this.element.find(this.options.updateCartActionContainer).val();

if (!this.options.validationURL || action === 'empty_cart') {
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
*/
namespace Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier;

use Magento\Catalog\Model\Locator\LocatorInterface;
use Magento\Catalog\Model\Product\Attribute\Backend\Sku;
use Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\AbstractModifier;
use Magento\Framework\UrlInterface;
use Magento\Ui\Component\Container;
use Magento\Ui\Component\Form;
use Magento\Ui\Component\DynamicRows;
use Magento\Ui\Component\Form;
use Magento\Ui\Component\Modal;
use Magento\Framework\UrlInterface;
use Magento\Catalog\Model\Locator\LocatorInterface;

/**
* Data provider for Configurable panel
Expand Down Expand Up @@ -90,15 +90,15 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function modifyData(array $data)
{
return $data;
}

/**
* {@inheritdoc}
* @inheritdoc
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
public function modifyMeta(array $meta)
Expand Down Expand Up @@ -197,7 +197,7 @@ public function modifyMeta(array $meta)
'autoRender' => false,
'componentType' => 'insertListing',
'component' => 'Magento_ConfigurableProduct/js'
.'/components/associated-product-insert-listing',
. '/components/associated-product-insert-listing',
'dataScope' => $this->associatedListingPrefix
. static::ASSOCIATED_PRODUCT_LISTING,
'externalProvider' => $this->associatedListingPrefix
Expand Down Expand Up @@ -328,14 +328,12 @@ protected function getButtonSet()
'component' => 'Magento_Ui/js/form/components/button',
'actions' => [
[
'targetName' =>
$this->dataScopeName . '.configurableModal',
'targetName' => $this->dataScopeName . '.configurableModal',
'actionName' => 'trigger',
'params' => ['active', true],
],
[
'targetName' =>
$this->dataScopeName . '.configurableModal',
'targetName' => $this->dataScopeName . '.configurableModal',
'actionName' => 'openModal',
],
],
Expand Down Expand Up @@ -574,6 +572,7 @@ protected function getColumn(
'dataType' => Form\Element\DataType\Text::NAME,
'dataScope' => $name,
'visibleIfCanEdit' => false,
'labelVisible' => false,
'imports' => [
'visible' => '!${$.provider}:${$.parentScope}.canEdit'
],
Expand All @@ -592,6 +591,7 @@ protected function getColumn(
'component' => 'Magento_Ui/js/form/components/group',
'label' => $label,
'dataScope' => '',
'showLabel' => false
];
$container['children'] = [
$name . '_edit' => $fieldEdit,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ protected function _construct()
{
parent::_construct();
$this->setId('customer_orders_grid');
$this->setDefaultSort('created_at', 'desc');
$this->setDefaultSort('created_at');
$this->setDefaultDir('desc');
$this->setUseAjax(true);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,8 @@ protected function _construct()
{
parent::_construct();
$this->setId('customer_view_cart_grid');
$this->setDefaultSort('added_at', 'desc');
$this->setDefaultSort('added_at');
$this->setDefaultDir('desc');
$this->setSortable(false);
$this->setPagerVisibility(false);
$this->setFilterVisibility(false);
Expand Down
119 changes: 84 additions & 35 deletions app/code/Magento/Sales/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use Magento\Framework\Setup\ModuleDataSetupInterface;
use Magento\Framework\Setup\UpgradeDataInterface;
use Magento\Quote\Model\QuoteFactory;
use Magento\Sales\Model\Order\Address;
use Magento\Sales\Model\OrderFactory;
use Magento\Sales\Model\ResourceModel\Order\Address\CollectionFactory as AddressCollectionFactory;

Expand Down Expand Up @@ -42,27 +43,14 @@ class UpgradeData implements UpgradeDataInterface
*/
private $aggregatedFieldConverter;

/**
* @var AddressCollectionFactory
*/
private $addressCollectionFactory;

/**
* @var OrderFactory
*/
private $orderFactory;

/**
* @var QuoteFactory
*/
private $quoteFactory;

/**
* @var State
*/
private $state;

/**
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*
* @param SalesSetupFactory $salesSetupFactory
* @param Config $eavConfig
* @param AggregatedFieldDataConverter $aggregatedFieldConverter
Expand All @@ -83,9 +71,6 @@ public function __construct(
$this->salesSetupFactory = $salesSetupFactory;
$this->eavConfig = $eavConfig;
$this->aggregatedFieldConverter = $aggregatedFieldConverter;
$this->addressCollectionFactory = $addressCollFactory;
$this->orderFactory = $orderFactory;
$this->quoteFactory = $quoteFactory;
$this->state = $state;
}

Expand Down Expand Up @@ -125,6 +110,7 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
* @param string $setupVersion
* @param SalesSetup $salesSetup
* @return void
* @throws \Magento\Framework\DB\FieldDataConversionException
*/
private function convertSerializedDataToJson($setupVersion, SalesSetup $salesSetup)
{
Expand Down Expand Up @@ -173,32 +159,95 @@ private function convertSerializedDataToJson($setupVersion, SalesSetup $salesSet

/**
* Fill quote_address_id in table sales_order_address if it is empty.
*
* @param ModuleDataSetupInterface $setup
*/
public function fillQuoteAddressIdInSalesOrderAddress(ModuleDataSetupInterface $setup)
{
$addressTable = $setup->getTable('sales_order_address');
$updateOrderAddress = $setup->getConnection()
$this->fillQuoteAddressIdInSalesOrderAddressByType($setup, Address::TYPE_SHIPPING);
$this->fillQuoteAddressIdInSalesOrderAddressByType($setup, Address::TYPE_BILLING);
}

/**
* @param ModuleDataSetupInterface $setup
* @param string $addressType
*/
private function fillQuoteAddressIdInSalesOrderAddressByType(ModuleDataSetupInterface $setup, $addressType)
{
$salesConnection = $setup->getConnection('sales');

$orderTable = $setup->getTable('sales_order', 'sales');
$orderAddressTable = $setup->getTable('sales_order_address', 'sales');

$query = $salesConnection
->select()
->from(
['sales_order_address' => $orderAddressTable],
['entity_id', 'address_type']
)
->joinInner(
['sales_order' => $setup->getTable('sales_order')],
$addressTable . '.parent_id = sales_order.entity_id',
['quote_address_id' => 'quote_address.address_id']
['sales_order' => $orderTable],
'sales_order_address.parent_id = sales_order.entity_id',
['quote_id' => 'sales_order.quote_id']
)
->where('sales_order_address.quote_address_id IS NULL')
->where('sales_order_address.address_type = ?', $addressType)
->order('sales_order_address.entity_id');

$batchSize = 5000;
$result = $salesConnection->query($query);
$count = $result->rowCount();
$batches = ceil($count / $batchSize);

for ($batch = $batches; $batch > 0; $batch--) {
$query->limitPage($batch, $batchSize);
$result = $salesConnection->fetchAssoc($query);

$this->fillQuoteAddressIdInSalesOrderAddressProcessBatch($setup, $result, $addressType);
}
}

/**
* @param ModuleDataSetupInterface $setup
* @param array $orderAddresses
* @param string $addressType
*/
private function fillQuoteAddressIdInSalesOrderAddressProcessBatch(
ModuleDataSetupInterface $setup,
array $orderAddresses,
$addressType
) {
$salesConnection = $setup->getConnection('sales');
$quoteConnection = $setup->getConnection('checkout');

$quoteAddressTable = $setup->getTable('quote_address', 'checkout');
$quoteTable = $setup->getTable('quote', 'checkout');
$salesOrderAddressTable = $setup->getTable('sales_order_address', 'sales');

$query = $quoteConnection
->select()
->from(
['quote_address' => $quoteAddressTable],
['quote_id', 'address_id']
)
->joinInner(
['quote_address' => $setup->getTable('quote_address')],
'sales_order.quote_id = quote_address.quote_id
AND ' . $addressTable . '.address_type = quote_address.address_type',
['quote' => $quoteTable],
'quote_address.quote_id = quote.entity_id',
[]
)
->where(
$addressTable . '.quote_address_id IS NULL'
);
$updateOrderAddress = $setup->getConnection()->updateFromSelect(
$updateOrderAddress,
$addressTable
);
$setup->getConnection()->query($updateOrderAddress);
->where('quote.entity_id in (?)', array_column($orderAddresses, 'quote_id'))
->where('address_type = ?', $addressType);

$quoteAddresses = $quoteConnection->fetchAssoc($query);

foreach ($orderAddresses as $orderAddress) {
$bind = [
'quote_address_id' => $quoteAddresses[$orderAddress['quote_id']]['address_id'] ?? null,
];
$where = [
'entity_id = ?' => $orderAddress['entity_id']
];

$salesConnection->update($salesOrderAddressTable, $bind, $where);
}
}
}
Loading

0 comments on commit 30ed829

Please sign in to comment.