Skip to content

Commit c0fc5b2

Browse files
committed
Merge pull request #328 from magento-firedrakes/CatalogStaging
[Firedrakes] Catalog staging
2 parents d3be453 + 1a8696c commit c0fc5b2

File tree

92 files changed

+1367
-403
lines changed

Some content is hidden

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

92 files changed

+1367
-403
lines changed

app/code/Magento/Bundle/Model/LinkManagement.php

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@
66
*/
77
namespace Magento\Bundle\Model;
88

9+
use Magento\Catalog\Api\Data\ProductInterface;
910
use Magento\Catalog\Api\ProductRepositoryInterface;
1011
use Magento\Framework\Exception\CouldNotSaveException;
1112
use Magento\Framework\Exception\InputException;
13+
use Magento\Framework\Model\Entity\MetadataPool;
1214

1315
/**
1416
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
@@ -45,14 +47,20 @@ class LinkManagement implements \Magento\Bundle\Api\ProductLinkManagementInterfa
4547
*/
4648
protected $dataObjectHelper;
4749

50+
/**
51+
* @var MetadataPool
52+
*/
53+
protected $metadataPool;
54+
4855
/**
4956
* @param ProductRepositoryInterface $productRepository
5057
* @param \Magento\Bundle\Api\Data\LinkInterfaceFactory $linkFactory
51-
* @param \Magento\Bundle\Model\ResourceModel\BundleFactory $bundleFactory
5258
* @param \Magento\Bundle\Model\SelectionFactory $bundleSelection
59+
* @param \Magento\Bundle\Model\ResourceModel\BundleFactory $bundleFactory
5360
* @param \Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $optionCollection
5461
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
5562
* @param \Magento\Framework\Api\DataObjectHelper $dataObjectHelper
63+
* @param MetadataPool $metadataPool
5664
*/
5765
public function __construct(
5866
ProductRepositoryInterface $productRepository,
@@ -61,7 +69,8 @@ public function __construct(
6169
\Magento\Bundle\Model\ResourceModel\BundleFactory $bundleFactory,
6270
\Magento\Bundle\Model\ResourceModel\Option\CollectionFactory $optionCollection,
6371
\Magento\Store\Model\StoreManagerInterface $storeManager,
64-
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper
72+
\Magento\Framework\Api\DataObjectHelper $dataObjectHelper,
73+
MetadataPool $metadataPool
6574
) {
6675
$this->productRepository = $productRepository;
6776
$this->linkFactory = $linkFactory;
@@ -70,6 +79,7 @@ public function __construct(
7079
$this->optionCollection = $optionCollection;
7180
$this->storeManager = $storeManager;
7281
$this->dataObjectHelper = $dataObjectHelper;
82+
$this->metadataPool = $metadataPool;
7383
}
7484

7585
/**
@@ -137,12 +147,12 @@ public function saveChild(
137147
if (!$selectionModel->getId()) {
138148
throw new InputException(__('Can not find product link with id "%1"', [$linkedProduct->getId()]));
139149
}
140-
150+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
141151
$selectionModel = $this->mapProductLinkToSelectionModel(
142152
$selectionModel,
143153
$linkedProduct,
144154
$linkProductModel->getId(),
145-
$product->getId()
155+
$product->getData($linkField)
146156
);
147157

148158
try {
@@ -221,9 +231,10 @@ public function addChild(
221231
);
222232
}
223233

234+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
224235
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
225236
$resource = $this->bundleFactory->create();
226-
$selections = $resource->getSelectionsData($product->getId());
237+
$selections = $resource->getSelectionsData($product->getData($linkField));
227238
/** @var \Magento\Catalog\Model\Product $linkProductModel */
228239
$linkProductModel = $this->productRepository->get($linkedProduct->getSku());
229240
if ($linkProductModel->isComposite()) {
@@ -232,7 +243,7 @@ public function addChild(
232243
if ($selections) {
233244
foreach ($selections as $selection) {
234245
if ($selection['option_id'] == $optionId &&
235-
$selection['product_id'] == $linkProductModel->getId()) {
246+
$selection['product_id'] == $linkProductModel->getEntityId()) {
236247
throw new CouldNotSaveException(
237248
__(
238249
'Child with specified sku: "%1" already assigned to product: "%2"',
@@ -242,19 +253,18 @@ public function addChild(
242253
}
243254
}
244255
}
245-
246256
$selectionModel = $this->bundleSelection->create();
247257
$selectionModel = $this->mapProductLinkToSelectionModel(
248258
$selectionModel,
249259
$linkedProduct,
250-
$linkProductModel->getId(),
251-
$product->getId()
260+
$linkProductModel->getEntityId(),
261+
$product->getData($linkField)
252262
);
253263
$selectionModel->setOptionId($optionId);
254264

255265
try {
256266
$selectionModel->save();
257-
$resource->addProductRelation($product->getId(), $linkProductModel->getId());
267+
$resource->addProductRelation($product->getData($linkField), $linkProductModel->getEntityId());
258268
} catch (\Exception $e) {
259269
throw new CouldNotSaveException(__('Could not save child: "%1"', $e->getMessage()), $e);
260270
}
@@ -293,10 +303,11 @@ public function removeChild($sku, $optionId, $childSku)
293303
__('Requested bundle option product doesn\'t exist')
294304
);
295305
}
306+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
296307
/* @var $resource \Magento\Bundle\Model\ResourceModel\Bundle */
297308
$resource = $this->bundleFactory->create();
298-
$resource->dropAllUnneededSelections($product->getId(), $excludeSelectionIds);
299-
$resource->removeProductRelations($product->getId(), array_unique($usedProductIds));
309+
$resource->dropAllUnneededSelections($product->getData($linkField), $excludeSelectionIds);
310+
$resource->removeProductRelations($product->getData($linkField), array_unique($usedProductIds));
300311

301312
return true;
302313
}

app/code/Magento/Bundle/Model/Plugin/Product.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public function afterGetIdentities(
3232
CatalogProduct $product,
3333
array $identities
3434
) {
35-
foreach ($this->type->getParentIdsByChild($product->getId()) as $parentId) {
35+
foreach ($this->type->getParentIdsByChild($product->getEntityId()) as $parentId) {
3636
$identities[] = CatalogProduct::CACHE_TAG . '_' . $parentId;
3737
}
3838
return $identities;

app/code/Magento/Bundle/Model/Product/Type.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,7 @@ public function getOptionsCollection($product)
425425
/** @var \Magento\Bundle\Model\ResourceModel\Option\Collection $optionsCollection */
426426
$optionsCollection = $this->_bundleOption->create()
427427
->getResourceCollection();
428-
$optionsCollection->setProductIdFilter($product->getId());
428+
$optionsCollection->setProductIdFilter($product->getEntityId());
429429
$this->setStoreFilter($product->getStoreId(), $product);
430430
$optionsCollection->setPositionOrder();
431431
$storeId = $this->getStoreFilter($product);

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Price.php

Lines changed: 23 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Bundle\Model\ResourceModel\Indexer;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
810
/**
911
* Bundle products Price indexer resource model
1012
*
@@ -132,7 +134,7 @@ protected function _prepareBundlePriceByType($priceType, $entityIds = null)
132134
['customer_group_id']
133135
);
134136
$this->_addWebsiteJoinToSelect($select, true);
135-
$this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', 'e.entity_id');
137+
$this->_addProductWebsiteJoinToSelect($select, 'cw.website_id', "e.entity_id");
136138
$select->columns(
137139
'website_id',
138140
'cw'
@@ -155,9 +157,10 @@ protected function _prepareBundlePriceByType($priceType, $entityIds = null)
155157
'=?',
156158
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
157159
);
158-
$this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $statusCond, true);
160+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
161+
$this->_addAttributeToSelect($select, 'status', "e.$linkField", 'cs.store_id', $statusCond, true);
159162
if ($this->moduleManager->isEnabled('Magento_Tax')) {
160-
$taxClassId = $this->_addAttributeToSelect($select, 'tax_class_id', 'e.entity_id', 'cs.store_id');
163+
$taxClassId = $this->_addAttributeToSelect($select, 'tax_class_id', "e.$linkField", 'cs.store_id');
161164
} else {
162165
$taxClassId = new \Zend_Db_Expr('0');
163166
}
@@ -171,12 +174,12 @@ protected function _prepareBundlePriceByType($priceType, $entityIds = null)
171174
}
172175

173176
$priceTypeCond = $connection->quoteInto('=?', $priceType);
174-
$this->_addAttributeToSelect($select, 'price_type', 'e.entity_id', 'cs.store_id', $priceTypeCond);
177+
$this->_addAttributeToSelect($select, 'price_type', "e.$linkField", 'cs.store_id', $priceTypeCond);
175178

176-
$price = $this->_addAttributeToSelect($select, 'price', 'e.entity_id', 'cs.store_id');
177-
$specialPrice = $this->_addAttributeToSelect($select, 'special_price', 'e.entity_id', 'cs.store_id');
178-
$specialFrom = $this->_addAttributeToSelect($select, 'special_from_date', 'e.entity_id', 'cs.store_id');
179-
$specialTo = $this->_addAttributeToSelect($select, 'special_to_date', 'e.entity_id', 'cs.store_id');
179+
$price = $this->_addAttributeToSelect($select, 'price', "e.$linkField", 'cs.store_id');
180+
$specialPrice = $this->_addAttributeToSelect($select, 'special_price', "e.$linkField", 'cs.store_id');
181+
$specialFrom = $this->_addAttributeToSelect($select, 'special_from_date', "e.$linkField", 'cs.store_id');
182+
$specialTo = $this->_addAttributeToSelect($select, 'special_to_date', "e.$linkField", 'cs.store_id');
180183
$curentDate = new \Zend_Db_Expr('cwd.website_date');
181184

182185
$specialExpr = $connection->getCheckSql(
@@ -401,12 +404,17 @@ protected function _calculateBundleSelectionPrice($priceType)
401404
);
402405
}
403406

407+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
404408
$select = $connection->select()->from(
405409
['i' => $this->_getBundlePriceTable()],
406410
['entity_id', 'customer_group_id', 'website_id']
411+
)->join(
412+
['parent_product' => $this->getTable('catalog_product_entity')],
413+
'parent_product.entity_id = i.entity_id',
414+
[]
407415
)->join(
408416
['bo' => $this->getTable('catalog_product_bundle_option')],
409-
'bo.parent_id = i.entity_id',
417+
"bo.parent_id = parent_product.$linkField",
410418
['option_id']
411419
)->join(
412420
['bs' => $this->getTable('catalog_product_bundle_selection')],
@@ -476,14 +484,14 @@ protected function _prepareBundlePrice($entityIds = null)
476484
protected function _prepareTierPriceIndex($entityIds = null)
477485
{
478486
$connection = $this->getConnection();
479-
487+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
480488
// remove index by bundle products
481489
$select = $connection->select()->from(
482490
['i' => $this->_getTierPriceIndexTable()],
483491
null
484492
)->join(
485493
['e' => $this->getTable('catalog_product_entity')],
486-
'i.entity_id=e.entity_id',
494+
"i.entity_id=e.$linkField",
487495
[]
488496
)->where(
489497
'e.type_id=?',
@@ -492,13 +500,12 @@ protected function _prepareTierPriceIndex($entityIds = null)
492500
$query = $select->deleteFromSelect('i');
493501
$connection->query($query);
494502

495-
$productIdField = $this->getProductIdFieldName();
496503
$select = $connection->select()->from(
497504
['tp' => $this->getTable('catalog_product_entity_tier_price')],
498-
[$productIdField]
505+
[$linkField]
499506
)->join(
500507
['e' => $this->getTable('catalog_product_entity')],
501-
"tp.{$productIdField} = e.{$productIdField}",
508+
"tp.{$linkField} = e.{$linkField}",
502509
[]
503510
)->join(
504511
['cg' => $this->getTable('customer_group')],
@@ -516,26 +523,16 @@ protected function _prepareTierPriceIndex($entityIds = null)
516523
)->columns(
517524
new \Zend_Db_Expr('MIN(tp.value)')
518525
)->group(
519-
["tp.{$productIdField}", 'cg.customer_group_id', 'cw.website_id']
526+
["tp.{$linkField}", 'cg.customer_group_id', 'cw.website_id']
520527
);
521528

522529
if (!empty($entityIds)) {
523-
$select->where("tp.{$productIdField} IN(?)", $entityIds);
530+
$select->where("tp.{$linkField} IN(?)", $entityIds);
524531
}
525532

526533
$query = $select->insertFromSelect($this->_getTierPriceIndexTable());
527534
$connection->query($query);
528535

529536
return $this;
530537
}
531-
532-
/**
533-
* @return string
534-
*/
535-
protected function getProductIdFieldName()
536-
{
537-
$table = $this->getTable('catalog_product_entity');
538-
$indexList = $this->getConnection()->getIndexList($table);
539-
return $indexList[$this->getConnection()->getPrimaryKeyName($table)]['COLUMNS_LIST'][0];
540-
}
541538
}

app/code/Magento/Bundle/Model/ResourceModel/Indexer/Stock.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
*/
66
namespace Magento\Bundle\Model\ResourceModel\Indexer;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
810
/**
911
* Bundle Stock Status Indexer Resource Model
1012
*
@@ -45,11 +47,17 @@ protected function _getBundleOptionTable()
4547
protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryTable = false)
4648
{
4749
$this->_cleanBundleOptionStockData();
50+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
4851
$idxTable = $usePrimaryTable ? $this->getMainTable() : $this->getIdxTable();
4952
$connection = $this->getConnection();
5053
$select = $connection->select()->from(
54+
['product' => $this->getTable('catalog_product_entity')],
55+
['entity_id']
56+
);
57+
$select->join(
5158
['bo' => $this->getTable('catalog_product_bundle_option')],
52-
['parent_id']
59+
"bo.parent_id = product.$linkField",
60+
[]
5361
);
5462
$this->_addWebsiteJoinToSelect($select, false);
5563
$status = new \Zend_Db_Expr(
@@ -77,13 +85,13 @@ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryT
7785
)->where(
7886
'cw.website_id != 0'
7987
)->group(
80-
['bo.parent_id', 'cw.website_id', 'cis.stock_id', 'bo.option_id']
88+
['product.entity_id', 'cw.website_id', 'cis.stock_id', 'bo.option_id']
8189
)->columns(
8290
['option_id' => 'bo.option_id', 'status' => $status]
8391
);
8492

8593
if ($entityIds !== null) {
86-
$select->where('bo.parent_id IN(?)', $entityIds);
94+
$select->where('product.entity_id IN(?)', $entityIds);
8795
}
8896

8997
// clone select for bundle product without required bundle options
@@ -110,7 +118,7 @@ protected function _prepareBundleOptionStockData($entityIds = null, $usePrimaryT
110118
protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = false)
111119
{
112120
$this->_prepareBundleOptionStockData($entityIds, $usePrimaryTable);
113-
121+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
114122
$connection = $this->getConnection();
115123
$select = $connection->select()->from(
116124
['e' => $this->getTable('catalog_product_entity')],
@@ -148,7 +156,7 @@ protected function _getStockStatusSelect($entityIds = null, $usePrimaryTable = f
148156
'=?',
149157
\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED
150158
);
151-
$this->_addAttributeToSelect($select, 'status', 'e.entity_id', 'cs.store_id', $condition);
159+
$this->_addAttributeToSelect($select, 'status', "e.$linkField", 'cs.store_id', $condition);
152160

153161
if ($this->_isManageStock()) {
154162
$statusExpr = $connection->getCheckSql(

app/code/Magento/Bundle/Model/ResourceModel/Option.php

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
*/
66
namespace Magento\Bundle\Model\ResourceModel;
77

8+
use Magento\Catalog\Api\Data\ProductInterface;
9+
use Magento\Framework\Model\Entity\MetadataPool;
10+
811
/**
912
* Bundle Option Resource Model
1013
*
@@ -17,18 +20,26 @@ class Option extends \Magento\Framework\Model\ResourceModel\Db\AbstractDb
1720
*/
1821
private $validator;
1922

23+
/**
24+
* @var MetadataPool
25+
*/
26+
private $metadataPool;
27+
2028
/**
2129
* @param \Magento\Framework\Model\ResourceModel\Db\Context $context
2230
* @param \Magento\Bundle\Model\Option\Validator $validator
31+
* @param MetadataPool $metadataPool
2332
* @param string $connectionName
2433
*/
2534
public function __construct(
2635
\Magento\Framework\Model\ResourceModel\Db\Context $context,
2736
\Magento\Bundle\Model\Option\Validator $validator,
37+
MetadataPool $metadataPool,
2838
$connectionName = null
2939
) {
3040
parent::__construct($context, $connectionName);
3141
$this->validator = $validator;
42+
$this->metadataPool = $metadataPool;
3243
}
3344

3445
/**
@@ -127,6 +138,7 @@ public function getSearchableData($productId, $storeId)
127138
'option_title_default.title'
128139
);
129140
$bind = ['store_id' => $storeId, 'product_id' => $productId];
141+
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
130142
$select = $connection->select()
131143
->from(
132144
['opt' => $this->getMainTable()],
@@ -142,8 +154,13 @@ public function getSearchableData($productId, $storeId)
142154
'option_title_store.option_id = opt.option_id AND option_title_store.store_id = :store_id',
143155
['title' => $title]
144156
)
157+
->join(
158+
['e' => $this->getTable('catalog_product_entity')],
159+
"e.$linkField = opt.parent_id",
160+
[]
161+
)
145162
->where(
146-
'opt.parent_id=:product_id'
163+
'e.entity_id=:product_id'
147164
);
148165
if (!($searchData = $connection->fetchCol($select, $bind))) {
149166
$searchData = [];

0 commit comments

Comments
 (0)