Skip to content

Commit df876bb

Browse files
[Magento Community Engineering] Community Contributions - 2.3-develop
- merged latest code from mainline branch
2 parents 7b1f571 + dc2ad7c commit df876bb

File tree

17 files changed

+328
-87
lines changed

17 files changed

+328
-87
lines changed

app/code/Magento/CatalogImportExport/Model/Import/Product.php

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3062,6 +3062,8 @@ private function getValidationErrorLevel($sku): string
30623062
* @param int $nextLinkId
30633063
* @param array $positionAttrId
30643064
* @return void
3065+
* @throws LocalizedException
3066+
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
30653067
*/
30663068
private function processLinkBunches(
30673069
array $bunch,
@@ -3072,6 +3074,7 @@ private function processLinkBunches(
30723074
$productIds = [];
30733075
$linkRows = [];
30743076
$positionRows = [];
3077+
$linksToDelete = [];
30753078

30763079
$bunch = array_filter($bunch, [$this, 'isRowAllowedToImport'], ARRAY_FILTER_USE_BOTH);
30773080
foreach ($bunch as $rowData) {
@@ -3088,10 +3091,15 @@ function ($linkName) use ($rowData) {
30883091
);
30893092
foreach ($linkNameToId as $linkName => $linkId) {
30903093
$linkSkus = explode($this->getMultipleValueSeparator(), $rowData[$linkName . 'sku']);
3094+
//process empty value
3095+
if (!empty($linkSkus[0]) && $linkSkus[0] === $this->getEmptyAttributeValueConstant()) {
3096+
$linksToDelete[$linkId][] = $productId;
3097+
continue;
3098+
}
3099+
30913100
$linkPositions = !empty($rowData[$linkName . 'position'])
30923101
? explode($this->getMultipleValueSeparator(), $rowData[$linkName . 'position'])
30933102
: [];
3094-
30953103
$linkSkus = array_filter(
30963104
$linkSkus,
30973105
function ($linkedSku) use ($sku) {
@@ -3100,6 +3108,7 @@ function ($linkedSku) use ($sku) {
31003108
&& strcasecmp($linkedSku, $sku) !== 0;
31013109
}
31023110
);
3111+
31033112
foreach ($linkSkus as $linkedKey => $linkedSku) {
31043113
$linkedId = $this->getProductLinkedId($linkedSku);
31053114
if ($linkedId == null) {
@@ -3131,9 +3140,34 @@ function ($linkedSku) use ($sku) {
31313140
}
31323141
}
31333142
}
3143+
$this->deleteProductsLinks($resource, $linksToDelete);
31343144
$this->saveLinksData($resource, $productIds, $linkRows, $positionRows);
31353145
}
31363146

3147+
/**
3148+
* Delete links
3149+
*
3150+
* @param Link $resource
3151+
* @param array $linksToDelete
3152+
* @return void
3153+
* @throws LocalizedException
3154+
*/
3155+
private function deleteProductsLinks(Link $resource, array $linksToDelete)
3156+
{
3157+
if (!empty($linksToDelete) && Import::BEHAVIOR_APPEND === $this->getBehavior()) {
3158+
foreach ($linksToDelete as $linkTypeId => $productIds) {
3159+
if (!empty($productIds)) {
3160+
$whereLinkId = $this->_connection->quoteInto('link_type_id', $linkTypeId);
3161+
$whereProductId = $this->_connection->quoteInto('product_id IN (?)', array_unique($productIds));
3162+
$this->_connection->delete(
3163+
$resource->getMainTable(),
3164+
$whereLinkId . ' AND ' . $whereProductId
3165+
);
3166+
}
3167+
}
3168+
}
3169+
}
3170+
31373171
/**
31383172
* Fetches Product Links
31393173
*

app/code/Magento/CatalogRule/Controller/Adminhtml/Promo/Catalog/Save.php

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
use Magento\Framework\Registry;
1313
use Magento\Framework\Stdlib\DateTime\Filter\Date;
1414
use Magento\Framework\App\Request\DataPersistorInterface;
15+
use Magento\Framework\Stdlib\DateTime\TimezoneInterface;
1516

1617
/**
1718
* Save action for catalog rule
@@ -25,19 +26,27 @@ class Save extends \Magento\CatalogRule\Controller\Adminhtml\Promo\Catalog imple
2526
*/
2627
protected $dataPersistor;
2728

29+
/**
30+
* @var TimezoneInterface
31+
*/
32+
private $localeDate;
33+
2834
/**
2935
* @param Context $context
3036
* @param Registry $coreRegistry
3137
* @param Date $dateFilter
3238
* @param DataPersistorInterface $dataPersistor
39+
* @param TimezoneInterface $localeDate
3340
*/
3441
public function __construct(
3542
Context $context,
3643
Registry $coreRegistry,
3744
Date $dateFilter,
38-
DataPersistorInterface $dataPersistor
45+
DataPersistorInterface $dataPersistor,
46+
TimezoneInterface $localeDate
3947
) {
4048
$this->dataPersistor = $dataPersistor;
49+
$this->localeDate = $localeDate;
4150
parent::__construct($context, $coreRegistry, $dateFilter);
4251
}
4352

@@ -46,16 +55,15 @@ public function __construct(
4655
*
4756
* @return \Magento\Framework\App\ResponseInterface|\Magento\Framework\Controller\ResultInterface|void
4857
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
58+
* @SuppressWarnings(PHPMD.NPathComplexity)
4959
*/
5060
public function execute()
5161
{
5262
if ($this->getRequest()->getPostValue()) {
53-
5463
/** @var \Magento\CatalogRule\Api\CatalogRuleRepositoryInterface $ruleRepository */
5564
$ruleRepository = $this->_objectManager->get(
5665
\Magento\CatalogRule\Api\CatalogRuleRepositoryInterface::class
5766
);
58-
5967
/** @var \Magento\CatalogRule\Model\Rule $model */
6068
$model = $this->_objectManager->create(\Magento\CatalogRule\Model\Rule::class);
6169

@@ -65,7 +73,9 @@ public function execute()
6573
['request' => $this->getRequest()]
6674
);
6775
$data = $this->getRequest()->getPostValue();
68-
76+
if (!$this->getRequest()->getParam('from_date')) {
77+
$data['from_date'] = $this->localeDate->formatDate();
78+
}
6979
$filterValues = ['from_date' => $this->_dateFilter];
7080
if ($this->getRequest()->getParam('to_date')) {
7181
$filterValues['to_date'] = $this->_dateFilter;

app/code/Magento/CatalogRule/Model/Indexer/ReindexRuleProduct.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,9 @@ public function execute(Rule $rule, $batchCount, $useAdditionalTable = false)
101101
$scopeTz = new \DateTimeZone(
102102
$this->localeDate->getConfigTimezone(ScopeInterface::SCOPE_WEBSITE, $websiteId)
103103
);
104-
$fromTime = (new \DateTime($rule->getFromDate(), $scopeTz))->getTimestamp();
104+
$fromTime = $rule->getFromDate()
105+
? (new \DateTime($rule->getFromDate(), $scopeTz))->getTimestamp()
106+
: 0;
105107
$toTime = $rule->getToDate()
106108
? (new \DateTime($rule->getToDate(), $scopeTz))->getTimestamp() + IndexBuilder::SECONDS_IN_DAY - 1
107109
: 0;

app/code/Magento/CatalogRule/Pricing/Price/CatalogRulePrice.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,8 @@ public function getValue()
8585
{
8686
if (null === $this->value) {
8787
if ($this->product->hasData(self::PRICE_CODE)) {
88-
$this->value = (float)$this->product->getData(self::PRICE_CODE) ?: false;
88+
$value = $this->product->getData(self::PRICE_CODE);
89+
$this->value = $value ? (float)$value : false;
8990
} else {
9091
$this->value = $this->ruleResource->getRulePrice(
9192
$this->dateTime->scopeDate($this->storeManager->getStore()->getId()),

app/code/Magento/CatalogRule/Test/Unit/Pricing/Price/CatalogRulePriceTest.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,4 +176,17 @@ public function testGetAmountNoBaseAmount()
176176
$result = $this->object->getValue();
177177
$this->assertFalse($result);
178178
}
179+
180+
public function testGetValueWithNullAmount()
181+
{
182+
$catalogRulePrice = null;
183+
$convertedPrice = 0.0;
184+
185+
$this->saleableItemMock->expects($this->once())->method('hasData')
186+
->with('catalog_rule_price')->willReturn(true);
187+
$this->saleableItemMock->expects($this->once())->method('getData')
188+
->with('catalog_rule_price')->willReturn($catalogRulePrice);
189+
190+
$this->assertEquals($convertedPrice, $this->object->getValue());
191+
}
179192
}

app/code/Magento/CatalogSearch/Model/Layer/Filter/Attribute.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,15 +58,18 @@ public function apply(\Magento\Framework\App\RequestInterface $request)
5858
if (empty($attributeValue) && !is_numeric($attributeValue)) {
5959
return $this;
6060
}
61+
6162
$attribute = $this->getAttributeModel();
6263
/** @var \Magento\CatalogSearch\Model\ResourceModel\Fulltext\Collection $productCollection */
6364
$productCollection = $this->getLayer()
6465
->getProductCollection();
6566
$productCollection->addFieldToFilter($attribute->getAttributeCode(), $attributeValue);
66-
$label = $this->getOptionText($attributeValue);
67-
if (is_array($label)) {
68-
$label = implode(',', $label);
67+
68+
$labels = [];
69+
foreach ((array) $attributeValue as $value) {
70+
$labels[] = (array) $this->getOptionText($value);
6971
}
72+
$label = implode(',', array_unique(array_merge(...$labels)));
7073
$this->getLayer()
7174
->getState()
7275
->addFilter($this->_createItem($label, $attributeValue));

app/code/Magento/CatalogUrlRewrite/Observer/UrlRewriteHandler.php

Lines changed: 34 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@
77

88
namespace Magento\CatalogUrlRewrite\Observer;
99

10-
use Magento\Catalog\Model\Product;
1110
use Magento\Catalog\Model\Category;
11+
use Magento\Catalog\Model\Product;
1212
use Magento\Catalog\Model\ResourceModel\Product\Collection;
1313
use Magento\Catalog\Model\ResourceModel\Product\CollectionFactory;
1414
use Magento\CatalogUrlRewrite\Model\Category\ChildrenCategoriesProvider;
@@ -118,13 +118,15 @@ public function __construct(
118118
$this->productCollectionFactory = $productCollectionFactory;
119119
$this->categoryBasedProductRewriteGenerator = $categoryBasedProductRewriteGenerator;
120120

121-
$objectManager = ObjectManager::getInstance();
122-
$mergeDataProviderFactory = $mergeDataProviderFactory ?: $objectManager->get(MergeDataProviderFactory::class);
121+
$mergeDataProviderFactory = $mergeDataProviderFactory
122+
?? ObjectManager::getInstance()->get(MergeDataProviderFactory::class);
123123
$this->mergeDataProviderPrototype = $mergeDataProviderFactory->create();
124-
$this->serializer = $serializer ?: $objectManager->get(Json::class);
124+
$this->serializer = $serializer
125+
?? ObjectManager::getInstance()->get(Json::class);
125126
$this->productScopeRewriteGenerator = $productScopeRewriteGenerator
126-
?: $objectManager->get(ProductScopeRewriteGenerator::class);
127-
$this->scopeConfig = $scopeConfig ?? $objectManager->get(ScopeConfigInterface::class);
127+
?? ObjectManager::getInstance()->get(ProductScopeRewriteGenerator::class);
128+
$this->scopeConfig = $scopeConfig
129+
?? ObjectManager::getInstance()->get(ScopeConfigInterface::class);
128130
}
129131

130132
/**
@@ -207,18 +209,14 @@ public function deleteCategoryRewritesForChildren(Category $category)
207209
foreach ($categoryIds as $categoryId) {
208210
$this->urlPersist->deleteByData(
209211
[
210-
UrlRewrite::ENTITY_ID =>
211-
$categoryId,
212-
UrlRewrite::ENTITY_TYPE =>
213-
CategoryUrlRewriteGenerator::ENTITY_TYPE,
212+
UrlRewrite::ENTITY_ID => $categoryId,
213+
UrlRewrite::ENTITY_TYPE => CategoryUrlRewriteGenerator::ENTITY_TYPE,
214214
]
215215
);
216216
$this->urlPersist->deleteByData(
217217
[
218-
UrlRewrite::METADATA =>
219-
$this->serializer->serialize(['category_id' => $categoryId]),
220-
UrlRewrite::ENTITY_TYPE =>
221-
ProductUrlRewriteGenerator::ENTITY_TYPE,
218+
UrlRewrite::METADATA => $this->serializer->serialize(['category_id' => $categoryId]),
219+
UrlRewrite::ENTITY_TYPE => ProductUrlRewriteGenerator::ENTITY_TYPE,
222220
]
223221
);
224222
}
@@ -252,7 +250,7 @@ private function getCategoryProductsUrlRewrites(
252250
->addAttributeToSelect('url_key')
253251
->addAttributeToSelect('url_path');
254252

255-
foreach ($productCollection as $product) {
253+
foreach ($this->getProducts($productCollection) as $product) {
256254
if (isset($this->isSkippedProduct[$category->getEntityId()]) &&
257255
in_array($product->getId(), $this->isSkippedProduct[$category->getEntityId()])
258256
) {
@@ -270,6 +268,27 @@ private function getCategoryProductsUrlRewrites(
270268
return $mergeDataProvider->getData();
271269
}
272270

271+
/**
272+
* Get products from provided collection
273+
*
274+
* @param Collection $collection
275+
* @return \Generator|Product[]
276+
*/
277+
private function getProducts(Collection $collection): \Generator
278+
{
279+
$collection->setPageSize(1000);
280+
$pageCount = $collection->getLastPageNumber();
281+
$currentPage = 1;
282+
while ($currentPage <= $pageCount) {
283+
$collection->setCurPage($currentPage);
284+
foreach ($collection as $key => $product) {
285+
yield $key => $product;
286+
}
287+
$collection->clear();
288+
$currentPage++;
289+
}
290+
}
291+
273292
/**
274293
* Generates product URL rewrites.
275294
*

app/code/Magento/Dhl/Model/Carrier.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -940,7 +940,7 @@ protected function _getDimension($dimension, $configWeightUnit = false)
940940
);
941941
}
942942

943-
return sprintf('%.3f', $dimension);
943+
return round($dimension, 3);
944944
}
945945

946946
/**

app/code/Magento/Dhl/etc/config.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
<specificerrmsg>This shipping method is currently unavailable. If you would like to ship using this shipping method, please contact us.</specificerrmsg>
3333
<divide_order_weight>1</divide_order_weight>
3434
<unit_of_measure>K</unit_of_measure>
35-
<size>R</size>
35+
<size>0</size>
3636
<handling_type>F</handling_type>
3737
<handling_action>O</handling_action>
3838
<shipment_days>Mon,Tue,Wed,Thu,Fri</shipment_days>

app/code/Magento/PageCache/view/frontend/web/js/page-cache.js

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,11 +112,14 @@ define([
112112
* @private
113113
*/
114114
_create: function () {
115-
var formKey = $.mage.cookies.get('form_key');
115+
var formKey = $.mage.cookies.get('form_key'),
116+
options = {
117+
secure: window.cookiesConfig ? window.cookiesConfig.secure : false
118+
};
116119

117120
if (!formKey) {
118121
formKey = generateRandomString(this.options.allowedCharacters, this.options.length);
119-
$.mage.cookies.set('form_key', formKey);
122+
$.mage.cookies.set('form_key', formKey, options);
120123
}
121124
$(this.options.inputSelector).val(formKey);
122125
}

0 commit comments

Comments
 (0)