Skip to content

Commit

Permalink
Merge pull request magento#3363 from magento-tsg-csl3/2.3-develop-pr10
Browse files Browse the repository at this point in the history
[TSG-CSL3] 2.3-develop (pr10)
  • Loading branch information
viktym authored Oct 26, 2018
2 parents 5916c5a + 39317f7 commit eb27ac2
Show file tree
Hide file tree
Showing 12 changed files with 433 additions and 51 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
-->

<sections xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="../../../../../../../dev/tests/acceptance/vendor/magento/magento2-functional-testing-framework/src/Magento/FunctionalTestingFramework/Page/etc/SectionObject.xsd">
<section name="StorefrontMiniCartSection">
<element name="quantity" type="button" selector="span.counter-number"/>
<element name="show" type="button" selector="a.showcart"/>
<element name="goToCheckout" type="button" selector="#top-cart-btn-checkout" timeout="30"/>
</section>
</sections>
31 changes: 30 additions & 1 deletion app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -1640,7 +1640,16 @@ protected function _saveProducts()
}
$rowScope = $this->getRowScope($rowData);

$rowData[self::URL_KEY] = $this->getUrlKey($rowData);
$urlKey = $this->getUrlKey($rowData);
if (!empty($rowData[self::URL_KEY])) {
// If url_key column and its value were in the CSV file
$rowData[self::URL_KEY] = $urlKey;
} else if ($this->isNeedToChangeUrlKey($rowData)) {
// If url_key column was empty or even not declared in the CSV file but by the rules it is need to
// be setteed. In case when url_key is generating from name column we have to ensure that the bunch
// of products will pass for the event with url_key column.
$bunch[$rowNum][self::URL_KEY] = $rowData[self::URL_KEY] = $urlKey;
}

$rowSku = $rowData[self::COL_SKU];

Expand Down Expand Up @@ -2889,6 +2898,26 @@ protected function getResource()
return $this->_resource;
}

/**
* Whether a url key is needed to be change.
*
* @param array $rowData
* @return bool
*/
private function isNeedToChangeUrlKey(array $rowData): bool
{
$urlKey = $this->getUrlKey($rowData);
$productExists = $this->isSkuExist($rowData[self::COL_SKU]);
$markedToEraseUrlKey = isset($rowData[self::URL_KEY]);
// The product isn't new and the url key index wasn't marked for change.
if (!$urlKey && $productExists && !$markedToEraseUrlKey) {
// Seems there is no need to change the url key
return false;
}

return true;
}

/**
* Get product entity link field
*
Expand Down
13 changes: 11 additions & 2 deletions app/code/Magento/Checkout/Controller/Cart/Delete.php
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
<?php
/**
*
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Checkout\Controller\Cart;

use Magento\Framework\App\Action\HttpPostActionInterface as HttpPostActionInterface;

/**
* Action Delete.
*
* Deletes item from cart.
*/
class Delete extends \Magento\Checkout\Controller\Cart implements HttpPostActionInterface
{
/**
Expand All @@ -24,7 +28,12 @@ public function execute()
$id = (int)$this->getRequest()->getParam('id');
if ($id) {
try {
$this->cart->removeItem($id)->save();
$this->cart->removeItem($id);
// We should set Totals to be recollected once more because of Cart model as usually is loading
// before action executing and in case when triggerRecollect setted as true recollecting will
// executed and the flag will be true already.
$this->cart->getQuote()->setTotalsCollectedFlag(false);
$this->cart->save();
} catch (\Exception $e) {
$this->messageManager->addErrorMessage(__('We can\'t remove the item.'));
$this->_objectManager->get(\Psr\Log\LoggerInterface::class)->critical($e);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/
declare(strict_types=1);

namespace Magento\Quote\Model\Product\Plugin;

use Magento\Catalog\Model\Product\Attribute\Source\Status;
use Magento\Catalog\Model\Product\Action as ProductAction;
use Magento\Quote\Model\ResourceModel\Quote as QuoteResource;

/**
* Remove quote items after mass disabling products
*/
class MarkQuotesRecollectMassDisabled
{
/** @var QuoteResource$quoteResource */
private $quoteResource;

/**
* @param QuoteResource $quoteResource
*/
public function __construct(
QuoteResource $quoteResource
) {
$this->quoteResource = $quoteResource;
}

/**
* Clean quote items after mass disabling product
*
* @param \Magento\Catalog\Model\Product\Action $subject
* @param \Magento\Catalog\Model\Product\Action $result
* @param int[] $productIds
* @param int[] $attrData
* @param int $storeId
* @return \Magento\Catalog\Model\Product\Action
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function afterUpdateAttributes(
ProductAction $subject,
ProductAction $result,
$productIds,
$attrData,
$storeId
): ProductAction {
if (isset($attrData['status']) && $attrData['status'] === Status::STATUS_DISABLED) {
$this->quoteResource->markQuotesRecollect($productIds);
}

return $result;
}
}
11 changes: 10 additions & 1 deletion app/code/Magento/Quote/Model/Quote/TotalsCollector.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ public function __construct(
}

/**
* Collect quote totals.
*
* @param \Magento\Quote\Model\Quote $quote
* @return Address\Total
*/
Expand All @@ -115,6 +117,8 @@ public function collectQuoteTotals(\Magento\Quote\Model\Quote $quote)
}

/**
* Collect quote.
*
* @param \Magento\Quote\Model\Quote $quote
* @return \Magento\Quote\Model\Quote\Address\Total
*/
Expand Down Expand Up @@ -172,6 +176,8 @@ public function collect(\Magento\Quote\Model\Quote $quote)
}

/**
* Validate coupon code.
*
* @param \Magento\Quote\Model\Quote $quote
* @return $this
*/
Expand Down Expand Up @@ -203,11 +209,12 @@ protected function _validateCouponCode(\Magento\Quote\Model\Quote $quote)
*/
protected function _collectItemsQtys(\Magento\Quote\Model\Quote $quote)
{
$quoteItems = $quote->getAllVisibleItems();
$quote->setItemsCount(0);
$quote->setItemsQty(0);
$quote->setVirtualItemsQty(0);

foreach ($quote->getAllVisibleItems() as $item) {
foreach ($quoteItems as $item) {
if ($item->getParentItem()) {
continue;
}
Expand All @@ -231,6 +238,8 @@ protected function _collectItemsQtys(\Magento\Quote\Model\Quote $quote)
}

/**
* Collect address total.
*
* @param \Magento\Quote\Model\Quote $quote
* @param Address $address
* @return Address\Total
Expand Down
Loading

0 comments on commit eb27ac2

Please sign in to comment.