Skip to content

Commit d52672b

Browse files
committed
Merge remote-tracking branch 'origin/2.1.8-develop' into MAGETWO-61267
2 parents cafc21b + 38108c7 commit d52672b

File tree

152 files changed

+4431
-948
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+4431
-948
lines changed

app/code/Magento/AdvancedPricingImportExport/Model/Import/AdvancedPricing.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -542,19 +542,24 @@ protected function retrieveOldSkus()
542542
*/
543543
protected function processCountExistingPrices($prices, $table)
544544
{
545+
$oldSkus = $this->retrieveOldSkus();
546+
$existProductIds = array_intersect_key($oldSkus, $prices);
547+
if (!count($existProductIds)) {
548+
return $this;
549+
}
550+
545551
$tableName = $this->_resourceFactory->create()->getTable($table);
546552
$productEntityLinkField = $this->getProductEntityLinkField();
547553
$existingPrices = $this->_connection->fetchAssoc(
548554
$this->_connection->select()->from(
549555
$tableName,
550556
['value_id', $productEntityLinkField, 'all_groups', 'customer_group_id']
551-
)
557+
)->where($productEntityLinkField . ' IN (?)', $existProductIds)
552558
);
553-
$oldSkus = $this->retrieveOldSkus();
554559
foreach ($existingPrices as $existingPrice) {
555-
foreach ($oldSkus as $sku => $productId) {
556-
if ($existingPrice[$productEntityLinkField] == $productId && isset($prices[$sku])) {
557-
$this->incrementCounterUpdated($prices[$sku], $existingPrice);
560+
foreach ($prices as $sku => $skuPrices) {
561+
if (isset($oldSkus[$sku]) && $existingPrice[$productEntityLinkField] == $oldSkus[$sku]) {
562+
$this->incrementCounterUpdated($skuPrices, $existingPrice);
558563
}
559564
}
560565
}

app/code/Magento/Catalog/Block/Breadcrumbs.php

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ public function getTitleSeparator($store = null)
5454
*/
5555
protected function _prepareLayout()
5656
{
57+
$title = [];
5758
if ($breadcrumbsBlock = $this->getLayout()->getBlock('breadcrumbs')) {
5859
$breadcrumbsBlock->addCrumb(
5960
'home',
@@ -64,7 +65,6 @@ protected function _prepareLayout()
6465
]
6566
);
6667

67-
$title = [];
6868
$path = $this->_catalogData->getBreadcrumbPath();
6969

7070
foreach ($path as $name => $breadcrumb) {
@@ -73,7 +73,18 @@ protected function _prepareLayout()
7373
}
7474

7575
$this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title)));
76+
77+
return parent::_prepareLayout();
78+
}
79+
80+
$path = $this->_catalogData->getBreadcrumbPath();
81+
82+
foreach ($path as $name => $breadcrumb) {
83+
$title[] = $breadcrumb['label'];
7684
}
85+
86+
$this->pageConfig->getTitle()->set(join($this->getTitleSeparator(), array_reverse($title)));
87+
7788
return parent::_prepareLayout();
7889
}
7990
}

app/code/Magento/Catalog/Controller/Adminhtml/Product/Initialization/Helper.php

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,11 @@ class Helper
7474
* @var \Magento\Framework\Stdlib\DateTime\Filter\DateTime
7575
*/
7676
private $dateTimeFilter;
77+
78+
/**
79+
* @var \Magento\Catalog\Model\Product\LinkTypeProvider
80+
*/
81+
private $linkTypeProvider;
7782

7883
/**
7984
* Helper constructor.
@@ -83,21 +88,25 @@ class Helper
8388
* @param ProductLinks $productLinks
8489
* @param \Magento\Backend\Helper\Js $jsHelper
8590
* @param \Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
91+
* @param \Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider
8692
*/
8793
public function __construct(
8894
\Magento\Framework\App\RequestInterface $request,
8995
\Magento\Store\Model\StoreManagerInterface $storeManager,
9096
StockDataFilter $stockFilter,
9197
\Magento\Catalog\Model\Product\Initialization\Helper\ProductLinks $productLinks,
9298
\Magento\Backend\Helper\Js $jsHelper,
93-
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter
99+
\Magento\Framework\Stdlib\DateTime\Filter\Date $dateFilter,
100+
\Magento\Catalog\Model\Product\LinkTypeProvider $linkTypeProvider = null
94101
) {
95102
$this->request = $request;
96103
$this->storeManager = $storeManager;
97104
$this->stockFilter = $stockFilter;
98105
$this->productLinks = $productLinks;
99106
$this->jsHelper = $jsHelper;
100107
$this->dateFilter = $dateFilter;
108+
$this->linkTypeProvider = $linkTypeProvider ?: \Magento\Framework\App\ObjectManager::getInstance()
109+
->get(\Magento\Catalog\Model\Product\LinkTypeProvider::class);
101110
}
102111

103112
/**
@@ -247,11 +256,17 @@ protected function setProductLinks(\Magento\Catalog\Model\Product $product)
247256

248257
$product = $this->productLinks->initializeLinks($product, $links);
249258
$productLinks = $product->getProductLinks();
250-
$linkTypes = [
251-
'related' => $product->getRelatedReadonly(),
252-
'upsell' => $product->getUpsellReadonly(),
253-
'crosssell' => $product->getCrosssellReadonly()
254-
];
259+
$linkTypes = [];
260+
261+
/** @var \Magento\Catalog\Api\Data\ProductLinkTypeInterface $linkTypeObject */
262+
foreach ($this->linkTypeProvider->getItems() as $linkTypeObject) {
263+
$linkTypes[$linkTypeObject->getName()] = $product->getData($linkTypeObject->getName() . '_readonly');
264+
}
265+
266+
// skip linkTypes that were already processed on initializeLinks plugins
267+
foreach ($productLinks as $productLink) {
268+
unset($linkTypes[$productLink->getLinkType()]);
269+
}
255270

256271
foreach ($linkTypes as $linkType => $readonly) {
257272
if (isset($links[$linkType]) && !$readonly) {

app/code/Magento/Catalog/Model/Product/Copier.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99

1010
use Magento\Catalog\Api\Data\ProductInterface;
1111

12+
/**
13+
* Catalog product copier.
14+
*/
1215
class Copier
1316
{
1417
/**
@@ -54,12 +57,15 @@ public function copy(\Magento\Catalog\Model\Product $product)
5457
$product->getWebsiteIds();
5558
$product->getCategoryIds();
5659

60+
/** @var \Magento\Framework\EntityManager\EntityMetadataInterface $metadata */
61+
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
62+
5763
/** @var \Magento\Catalog\Model\Product $duplicate */
5864
$duplicate = $this->productFactory->create();
5965
$duplicate->setData($product->getData());
6066
$duplicate->setOptions([]);
6167
$duplicate->setIsDuplicate(true);
62-
$duplicate->setOriginalId($product->getEntityId());
68+
$duplicate->setOriginalLinkId($product->getData($metadata->getLinkField()));
6369
$duplicate->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_DISABLED);
6470
$duplicate->setCreatedAt(null);
6571
$duplicate->setUpdatedAt(null);
@@ -81,11 +87,11 @@ public function copy(\Magento\Catalog\Model\Product $product)
8187
}
8288
} while (!$isDuplicateSaved);
8389
$this->getOptionRepository()->duplicate($product, $duplicate);
84-
$metadata = $this->getMetadataPool()->getMetadata(ProductInterface::class);
8590
$product->getResource()->duplicate(
8691
$product->getData($metadata->getLinkField()),
8792
$duplicate->getData($metadata->getLinkField())
8893
);
94+
8995
return $duplicate;
9096
}
9197

@@ -97,8 +103,9 @@ private function getOptionRepository()
97103
{
98104
if (null === $this->optionRepository) {
99105
$this->optionRepository = \Magento\Framework\App\ObjectManager::getInstance()
100-
->get('Magento\Catalog\Model\Product\Option\Repository');
106+
->get(\Magento\Catalog\Model\Product\Option\Repository::class);
101107
}
108+
102109
return $this->optionRepository;
103110
}
104111

@@ -110,8 +117,9 @@ private function getMetadataPool()
110117
{
111118
if (null === $this->metadataPool) {
112119
$this->metadataPool = \Magento\Framework\App\ObjectManager::getInstance()
113-
->get('Magento\Framework\EntityManager\MetadataPool');
120+
->get(\Magento\Framework\EntityManager\MetadataPool::class);
114121
}
122+
115123
return $this->metadataPool;
116124
}
117125
}

app/code/Magento/Catalog/Model/Product/Gallery/CreateHandler.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,8 @@ protected function processNewImage($product, array &$image)
278278
}
279279

280280
/**
281+
* Duplicate product media gallery data.
282+
*
281283
* @param \Magento\Catalog\Model\Product $product
282284
* @return $this
283285
*/
@@ -294,7 +296,7 @@ protected function duplicate($product)
294296
$this->resourceModel->duplicate(
295297
$this->getAttribute()->getAttributeId(),
296298
isset($mediaGalleryData['duplicate']) ? $mediaGalleryData['duplicate'] : [],
297-
$product->getOriginalId(),
299+
$product->getOriginalLinkId(),
298300
$product->getData($this->metadata->getLinkField())
299301
);
300302

app/code/Magento/Catalog/Model/ResourceModel/Product/Collection.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2213,16 +2213,24 @@ public function addMediaGalleryData()
22132213
$linkField = $this->getMetadataPool()->getMetadata(ProductInterface::class)->getLinkField();
22142214
$items = $this->getItems();
22152215

2216-
$select->where('entity.' . $linkField . ' IN (?)', array_map(function ($item) {
2217-
return $item->getId();
2218-
}, $items));
2216+
$select->where(
2217+
'entity.' . $linkField . ' IN (?)',
2218+
array_map(
2219+
function ($item) use ($linkField) {
2220+
return $item->getData($linkField);
2221+
},
2222+
$items
2223+
)
2224+
);
22192225

22202226
foreach ($this->getConnection()->fetchAll($select) as $row) {
22212227
$mediaGalleries[$row[$linkField]][] = $row;
22222228
}
22232229

22242230
foreach ($items as $item) {
2225-
$mediaEntries = isset($mediaGalleries[$item->getId()]) ? $mediaGalleries[$item->getId()] : [];
2231+
$mediaEntries = isset($mediaGalleries[$item->getData($linkField)])
2232+
? $mediaGalleries[$item->getData($linkField)]
2233+
: [];
22262234
$this->getGalleryReadHandler()->addMediaDataToProduct($item, $mediaEntries);
22272235
}
22282236

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/AbstractEav.php

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,17 +197,25 @@ protected function _prepareRelationIndexSelect($parentIds = null)
197197
)->joinLeft(
198198
['e' => $this->getTable('catalog_product_entity')],
199199
'e.' . $linkField .' = l.parent_id',
200-
['e.entity_id as parent_id']
200+
[]
201201
)->join(
202202
['cs' => $this->getTable('store')],
203203
'',
204204
[]
205205
)->join(
206206
['i' => $idxTable],
207207
'l.child_id = i.entity_id AND cs.store_id = i.store_id',
208-
['attribute_id', 'store_id', 'value']
208+
[]
209209
)->group(
210-
['parent_id', 'i.attribute_id', 'i.store_id', 'i.value']
210+
['parent_id', 'i.attribute_id', 'i.store_id', 'i.value', 'l.child_id']
211+
)->columns(
212+
[
213+
'parent_id' => 'e.entity_id',
214+
'attribute_id' => 'i.attribute_id',
215+
'store_id' => 'i.store_id',
216+
'value' => 'i.value',
217+
'source_id' => 'l.child_id'
218+
]
211219
);
212220
if ($parentIds !== null) {
213221
$select->where('e.entity_id IN(?)', $parentIds);
@@ -222,7 +230,7 @@ protected function _prepareRelationIndexSelect($parentIds = null)
222230
'select' => $select,
223231
'entity_field' => new \Zend_Db_Expr('l.parent_id'),
224232
'website_field' => new \Zend_Db_Expr('cs.website_id'),
225-
'store_field' => new \Zend_Db_Expr('cs.store_id')
233+
'store_field' => new \Zend_Db_Expr('cs.store_id'),
226234
]
227235
);
228236

app/code/Magento/Catalog/Model/ResourceModel/Product/Indexer/Eav/Decimal.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
8585
'pdd.attribute_id',
8686
'cs.store_id',
8787
'value' => $productValueExpression,
88+
'source_id' => 'cpe.entity_id',
8889
]
8990
);
9091

@@ -116,7 +117,7 @@ protected function _prepareIndex($entityIds = null, $attributeId = null)
116117
'select' => $select,
117118
'entity_field' => new \Zend_Db_Expr('cpe.entity_id'),
118119
'website_field' => new \Zend_Db_Expr('cs.website_id'),
119-
'store_field' => new \Zend_Db_Expr('cs.store_id')
120+
'store_field' => new \Zend_Db_Expr('cs.store_id'),
120121
]
121122
);
122123

0 commit comments

Comments
 (0)