Skip to content

Commit

Permalink
Merge pull request #512 from magento-dragons/MAGETWO-52717
Browse files Browse the repository at this point in the history
[DRAGONS] Bugs fixing (P0)
- MAGETWO-52717 [GitHub] Configurable product disabling lowest price associated product still shows its price #4419
- MAGETWO-59315 Non consistent save Product Stock Item via Web API and repository directly
  • Loading branch information
slavvka committed Oct 19, 2016
2 parents 8d0dc6f + c921365 commit ed5eefb
Show file tree
Hide file tree
Showing 28 changed files with 835 additions and 128 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public function beforeSave($object)
if (isset($stockData['qty']) && $stockData['qty'] === '') {
$stockData['qty'] = null;
}
if ($object->getStockData() !== null || $stockData !== null) {
if ($object->getStockData() !== null && $stockData !== null) {
$object->setStockData(array_replace((array)$object->getStockData(), (array)$stockData));
}
$object->unsetData($this->getAttribute()->getAttributeCode());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\ResourceModel\Product;

use Magento\Framework\DB\Select;

/**
* Interface BaseSelectProcessorInterface
* @api
*/
interface BaseSelectProcessorInterface
{
/**
* Product table alias
*/
const PRODUCT_TABLE_ALIAS = 'child';

/**
* @param Select $select
* @return Select
*/
public function process(Select $select);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\Catalog\Model\ResourceModel\Product;

use Magento\Framework\DB\Select;
use Magento\Framework\Exception\InputException;

/**
* Class CompositeBaseSelectProcessor
*/
class CompositeBaseSelectProcessor implements BaseSelectProcessorInterface
{
/**
* @var BaseSelectProcessorInterface[]
*/
private $baseSelectProcessors;

/**
* @param BaseSelectProcessorInterface[] $baseSelectProcessors
* @throws InputException
*/
public function __construct(
array $baseSelectProcessors
) {
foreach ($baseSelectProcessors as $baseSelectProcessor) {
if (!$baseSelectProcessor instanceof BaseSelectProcessorInterface) {
throw new InputException(
__('Processor %1 doesn\'t implement BaseSelectProcessorInterface', get_class($baseSelectProcessor))
);
}
}
$this->baseSelectProcessors = $baseSelectProcessors;
}

/**
* @param Select $select
* @return Select
*/
public function process(Select $select)
{
foreach ($this->baseSelectProcessors as $baseSelectProcessor) {
$select = $baseSelectProcessor->process($select);
}
return $select;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
namespace Magento\Catalog\Model\ResourceModel\Product\Indexer;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Catalog\Model\ResourceModel\Product\BaseSelectProcessorInterface;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;

Expand All @@ -32,22 +33,31 @@ class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuild
*/
private $metadataPool;

/**
* @var BaseSelectProcessorInterface
*/
private $baseSelectProcessor;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
* @param BaseSelectProcessorInterface $baseSelectProcessor
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Magento\Customer\Model\Session $customerSession,
\Magento\Framework\EntityManager\MetadataPool $metadataPool
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
BaseSelectProcessorInterface $baseSelectProcessor = null
) {
$this->storeManager = $storeManager;
$this->resource = $resourceConnection;
$this->customerSession = $customerSession;
$this->metadataPool = $metadataPool;
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
}

/**
Expand All @@ -58,24 +68,27 @@ public function build($productId)
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$productTable = $this->resource->getTableName('catalog_product_entity');

return [$this->resource->getConnection()->select()
$priceSelect = $this->resource->getConnection()->select()
->from(['parent' => $productTable], '')
->joinInner(
['link' => $this->resource->getTableName('catalog_product_relation')],
"link.parent_id = parent.$linkField",
[]
)->joinInner(
['child' => $productTable],
"child.entity_id = link.child_id",
[BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS => $productTable],
sprintf('%s.entity_id = link.child_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
['entity_id']
)->joinInner(
['t' => $this->resource->getTableName('catalog_product_index_price')],
't.entity_id = child.entity_id',
sprintf('t.entity_id = %s.entity_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
[]
)->where('parent.entity_id = ? ', $productId)
)->where('parent.entity_id = ?', $productId)
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
->order('t.min_price ' . Select::SQL_ASC)
->limit(1)];
->limit(1);
$priceSelect = $this->baseSelectProcessor->process($priceSelect);

return [$priceSelect];
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;
use Magento\Store\Model\Store;

Expand Down Expand Up @@ -37,25 +38,34 @@ class LinkedProductSelectBuilderByBasePrice implements LinkedProductSelectBuilde
*/
private $metadataPool;

/**
* @var BaseSelectProcessorInterface
*/
private $baseSelectProcessor;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
* @param \Magento\Eav\Model\Config $eavConfig
* @param \Magento\Catalog\Helper\Data $catalogHelper
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
* @param BaseSelectProcessorInterface $baseSelectProcessor
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Magento\Eav\Model\Config $eavConfig,
\Magento\Catalog\Helper\Data $catalogHelper,
\Magento\Framework\EntityManager\MetadataPool $metadataPool
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
BaseSelectProcessorInterface $baseSelectProcessor = null
) {
$this->storeManager = $storeManager;
$this->resource = $resourceConnection;
$this->eavConfig = $eavConfig;
$this->catalogHelper = $catalogHelper;
$this->metadataPool = $metadataPool;
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
}

/**
Expand All @@ -74,18 +84,19 @@ public function build($productId)
"link.parent_id = parent.$linkField",
[]
)->joinInner(
['child' => $productTable],
"child.entity_id = link.child_id",
[BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS => $productTable],
sprintf('%s.entity_id = link.child_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS, $linkField),
['entity_id']
)->joinInner(
['t' => $priceAttribute->getBackendTable()],
"t.$linkField = child.$linkField",
sprintf('t.%s = %s.%1$s', $linkField, BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
[]
)->where('parent.entity_id = ? ', $productId)
)->where('parent.entity_id = ?', $productId)
->where('t.attribute_id = ?', $priceAttribute->getAttributeId())
->where('t.value IS NOT NULL')
->order('t.value ' . Select::SQL_ASC)
->limit(1);
$priceSelect = $this->baseSelectProcessor->process($priceSelect);

$priceSelectDefault = clone $priceSelect;
$priceSelectDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;
use Magento\Store\Model\Store;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBuilderInterface
{
/**
Expand Down Expand Up @@ -47,6 +51,11 @@ class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBui
*/
private $metadataPool;

/**
* @var BaseSelectProcessorInterface
*/
private $baseSelectProcessor;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
Expand All @@ -55,6 +64,7 @@ class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBui
* @param \Magento\Framework\Stdlib\DateTime $dateTime
* @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
* @param BaseSelectProcessorInterface $baseSelectProcessor
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
Expand All @@ -63,7 +73,8 @@ public function __construct(
\Magento\Catalog\Helper\Data $catalogHelper,
\Magento\Framework\Stdlib\DateTime $dateTime,
\Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
\Magento\Framework\EntityManager\MetadataPool $metadataPool
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
BaseSelectProcessorInterface $baseSelectProcessor = null
) {
$this->storeManager = $storeManager;
$this->resource = $resourceConnection;
Expand All @@ -72,6 +83,8 @@ public function __construct(
$this->dateTime = $dateTime;
$this->localeDate = $localeDate;
$this->metadataPool = $metadataPool;
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
}

/**
Expand All @@ -95,12 +108,12 @@ public function build($productId)
"link.parent_id = parent.$linkField",
[]
)->joinInner(
['child' => $productTable],
"child.entity_id = link.child_id",
[BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS => $productTable],
sprintf('%s.entity_id = link.child_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
['entity_id']
)->joinInner(
['t' => $specialPriceAttribute->getBackendTable()],
"t.$linkField = child.$linkField",
sprintf('t.%s = %s.%1$s', $linkField, BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
[]
)->joinLeft(
['special_from' => $specialPriceFromDate->getBackendTable()],
Expand All @@ -116,7 +129,7 @@ public function build($productId)
$specialPriceToDate->getAttributeId()
),
''
)->where('parent.entity_id = ? ', $productId)
)->where('parent.entity_id = ?', $productId)
->where('t.attribute_id = ?', $specialPriceAttribute->getAttributeId())
->where('t.value IS NOT NULL')
->where(
Expand All @@ -127,6 +140,7 @@ public function build($productId)
$currentDate
)->order('t.value ' . Select::SQL_ASC)
->limit(1);
$specialPrice = $this->baseSelectProcessor->process($specialPrice);

$specialPriceDefault = clone $specialPrice;
$specialPriceDefault->where('t.store_id = ?', Store::DEFAULT_STORE_ID);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
namespace Magento\Catalog\Model\ResourceModel\Product;

use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\Product;
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;

class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilderInterface
Expand Down Expand Up @@ -41,25 +41,34 @@ class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilde
*/
private $metadataPool;

/**
* @var BaseSelectProcessorInterface
*/
private $baseSelectProcessor;

/**
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Framework\App\ResourceConnection $resourceConnection
* @param \Magento\Customer\Model\Session $customerSession
* @param \Magento\Catalog\Helper\Data $catalogHelper
* @param \Magento\Framework\EntityManager\MetadataPool $metadataPool
* @param BaseSelectProcessorInterface $baseSelectProcessor
*/
public function __construct(
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Magento\Customer\Model\Session $customerSession,
\Magento\Catalog\Helper\Data $catalogHelper,
\Magento\Framework\EntityManager\MetadataPool $metadataPool
\Magento\Framework\EntityManager\MetadataPool $metadataPool,
BaseSelectProcessorInterface $baseSelectProcessor = null
) {
$this->storeManager = $storeManager;
$this->resource = $resourceConnection;
$this->customerSession = $customerSession;
$this->catalogHelper = $catalogHelper;
$this->metadataPool = $metadataPool;
$this->baseSelectProcessor = (null !== $baseSelectProcessor)
? $baseSelectProcessor : ObjectManager::getInstance()->get(BaseSelectProcessorInterface::class);
}

/**
Expand All @@ -77,18 +86,19 @@ public function build($productId)
"link.parent_id = parent.$linkField",
[]
)->joinInner(
['child' => $productTable],
"child.entity_id = link.child_id",
[BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS => $productTable],
sprintf('%s.entity_id = link.child_id', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
['entity_id']
)->joinInner(
['t' => $this->resource->getTableName('catalog_product_entity_tier_price')],
"t.$linkField = child.$linkField",
sprintf('t.%s = %s.%1$s', $linkField, BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS),
[]
)->where('parent.entity_id = ? ', $productId)
)->where('parent.entity_id = ?', $productId)
->where('t.all_groups = 1 OR customer_group_id = ?', $this->customerSession->getCustomerGroupId())
->where('t.qty = ?', 1)
->order('t.value ' . Select::SQL_ASC)
->limit(1);
$priceSelect = $this->baseSelectProcessor->process($priceSelect);

$priceSelectDefault = clone $priceSelect;
$priceSelectDefault->where('t.website_id = ?', self::DEFAULT_WEBSITE_ID);
Expand Down

0 comments on commit ed5eefb

Please sign in to comment.