Skip to content

Commit

Permalink
Merge pull request magento#5253 from magento-chaika/Chaika-PR24-2020-…
Browse files Browse the repository at this point in the history
…01-22

Chaika-PR24-2020-01-22
  • Loading branch information
dhorytskyi authored Jan 30, 2020
2 parents 2c553dd + 771ce44 commit e6e6725
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 229 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,13 @@
use Magento\Store\Model\Indexer\WebsiteDimensionProvider;
use Magento\Framework\Search\Request\IndexScopeResolverInterface;

/**
* Class LinkedProductSelectBuilderByIndexPrice
*
* Provide Select object for retrieve product id by index price.
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class LinkedProductSelectBuilderByIndexPrice implements LinkedProductSelectBuilderInterface
{
/**
Expand Down Expand Up @@ -83,13 +90,13 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function build($productId)
public function build(int $productId, int $storeId) : array
{
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$productTable = $this->resource->getTableName('catalog_product_entity');
$websiteId = $this->storeManager->getStore()->getWebsiteId();
$websiteId = $this->storeManager->getStore($storeId)->getWebsiteId();
$customerGroupId = $this->customerSession->getCustomerGroupId();

$priceSelect = $this->resource->getConnection()->select()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function __construct(
/**
* @inheritdoc
*/
public function build($productId)
public function build(int $productId, int $storeId) : array
{
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$priceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'price');
Expand Down Expand Up @@ -104,7 +104,7 @@ public function build($productId)

if (!$this->catalogHelper->isPriceGlobal()) {
$priceSelectStore = clone $priceSelect;
$priceSelectStore->where('t.store_id = ?', $this->storeManager->getStore()->getId());
$priceSelectStore->where('t.store_id = ?', $storeId);
$selects[] = $priceSelectStore;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@
use Magento\Store\Model\Store;

/**
* LinkedProductSelectBuilderBySpecialPrice
*
* Provide Select object for retrieve product id by special price
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
*/
class LinkedProductSelectBuilderBySpecialPrice implements LinkedProductSelectBuilderInterface
Expand Down Expand Up @@ -88,16 +92,16 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function build($productId)
public function build(int $productId, int $storeId) : array
{
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$connection = $this->resource->getConnection();
$specialPriceAttribute = $this->eavConfig->getAttribute(Product::ENTITY, 'special_price');
$specialPriceFromDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_from_date');
$specialPriceToDate = $this->eavConfig->getAttribute(Product::ENTITY, 'special_to_date');
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore($storeId));
$currentDate = $this->dateTime->formatDate($timestamp, false);
$productTable = $this->resource->getTableName('catalog_product_entity');

Expand Down Expand Up @@ -145,7 +149,7 @@ public function build($productId)

if (!$this->catalogHelper->isPriceGlobal()) {
$priceSelectStore = clone $specialPrice;
$priceSelectStore->where('t.store_id = ?', $this->storeManager->getStore()->getId());
$priceSelectStore->where('t.store_id = ?', $storeId);
$selects[] = $priceSelectStore;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,19 @@
use Magento\Framework\App\ObjectManager;
use Magento\Framework\DB\Select;

/**
* LinkedProductSelectBuilderByTierPrice
*
* Provide Select object for retrieve product id by tier price
*
* @SuppressWarnings(PHPMD.CookieAndSessionMisuse)
*/
class LinkedProductSelectBuilderByTierPrice implements LinkedProductSelectBuilderInterface
{
/**
* Default website id
*
* Constant represents default website id
*/
const DEFAULT_WEBSITE_ID = 0;

Expand Down Expand Up @@ -72,9 +81,9 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function build($productId)
public function build(int $productId, int $storeId) : array
{
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$productTable = $this->resource->getTableName('catalog_product_entity');
Expand Down Expand Up @@ -103,7 +112,7 @@ public function build($productId)

if (!$this->catalogHelper->isPriceGlobal()) {
$priceSelectStore = clone $priceSelect;
$priceSelectStore->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId());
$priceSelectStore->where('t.website_id = ?', $this->storeManager->getStore($storeId)->getWebsiteId());
$selects[] = $priceSelectStore;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@

namespace Magento\Catalog\Model\ResourceModel\Product;

/**
* Collect Select object for list of products
*/
class LinkedProductSelectBuilderComposite implements LinkedProductSelectBuilderInterface
{
/**
Expand All @@ -22,14 +25,15 @@ public function __construct($linkedProductSelectBuilder)
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function build($productId)
public function build(int $productId, int $storeId) : array
{
$selects = [];
foreach ($this->linkedProductSelectBuilder as $productSelectBuilder) {
$selects = array_merge($selects, $productSelectBuilder->build($productId));
$selects[] = $productSelectBuilder->build($productId, $storeId);
}
$selects = array_merge(...$selects);

return $selects;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,11 @@
interface LinkedProductSelectBuilderInterface
{
/**
* Build Select objects
*
* @param int $productId
* @param int $storeId
* @return \Magento\Framework\DB\Select[]
*/
public function build($productId);
public function build(int $productId, int $storeId) : array;
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,21 @@ class LinkedProductSelectBuilderByIndexPriceTest extends \PHPUnit\Framework\Test
*/
private $baseSelectProcessorMock;

/**
* @var \Magento\Framework\Search\Request\IndexScopeResolverInterface|\PHPUnit\Framework\MockObject\MockObject
*/
private $indexScopeResolverMock;

/**
* @var \Magento\Framework\Indexer\Dimension|\PHPUnit\Framework\MockObject\MockObject
*/
private $dimensionMock;

/**
* @var \Magento\Framework\Indexer\DimensionFactory|\PHPUnit\Framework\MockObject\MockObject
*/
private $dimensionFactoryMock;

/**
* @var \Magento\Catalog\Model\ResourceModel\Product\Indexer\LinkedProductSelectBuilderByIndexPrice
*/
Expand Down Expand Up @@ -85,6 +100,7 @@ protected function setUp()
public function testBuild()
{
$productId = 10;
$storeId = 1;
$metadata = $this->getMockBuilder(\Magento\Framework\EntityManager\EntityMetadataInterface::class)
->disableOriginalConstructor()
->getMockForAbstractClass();
Expand All @@ -108,6 +124,6 @@ public function testBuild()
$metadata->expects($this->once())->method('getLinkField')->willReturn('row_id');
$this->resourceMock->expects($this->any())->method('getTableName');
$this->baseSelectProcessorMock->expects($this->once())->method('process')->willReturnSelf();
$this->model->build($productId);
$this->model->build($productId, $storeId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -222,9 +222,11 @@ private function checkOptionsQtyIncrements(Item $quoteItem, array $options): voi
{
$removeErrors = true;
foreach ($options as $option) {
$optionValue = $option->getValue();
$optionQty = $quoteItem->getData('qty') * $optionValue;
$result = $this->stockState->checkQtyIncrements(
$option->getProduct()->getId(),
$quoteItem->getData('qty'),
$optionQty,
$option->getProduct()->getStore()->getWebsiteId()
);
if ($result->getHasError()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public function __construct(
/**
* @inheritdoc
*/
public function build($productId)
public function build(int $productId, int $storeId) : array
{
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore());
$timestamp = $this->localeDate->scopeTimeStamp($this->storeManager->getStore($storeId));
$currentDate = $this->dateTime->formatDate($timestamp, false);
$linkField = $this->metadataPool->getMetadata(ProductInterface::class)->getLinkField();
$productTable = $this->resource->getTableName('catalog_product_entity');
Expand All @@ -108,7 +108,7 @@ public function build($productId)
sprintf('t.product_id = %s.%s', BaseSelectProcessorInterface::PRODUCT_TABLE_ALIAS, $linkField),
[]
)->where('parent.entity_id = ?', $productId)
->where('t.website_id = ?', $this->storeManager->getStore()->getWebsiteId())
->where('t.website_id = ?', $this->storeManager->getStore($storeId)->getWebsiteId())
->where('t.customer_group_id = ?', $this->customerSession->getCustomerGroupId())
->where('t.rule_date = ?', $currentDate)
->order('t.rule_price ' . Select::SQL_ASC)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function build($productId)
public function build(int $productId, int $storeId) : array
{
$selects = $this->linkedProductSelectBuilder->build($productId);
$selects = $this->linkedProductSelectBuilder->build($productId, $storeId);

foreach ($selects as $select) {
$this->baseSelectProcessor->process($select);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,16 @@ public function __construct(
}

/**
* {@inheritdoc}
* @inheritdoc
*/
public function getProducts(ProductInterface $product)
{
$key = $this->storeManager->getStore()->getId() . '-' . $product->getId();
$productId = $product->getId();
$storeId = $product->getStoreId() ?: $this->storeManager->getStore()->getId();
$key = $storeId . '-' . $productId;
if (!isset($this->linkedProductMap[$key])) {
$productIds = $this->resource->getConnection()->fetchCol(
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($product->getId())) . ')'
'(' . implode(') UNION (', $this->linkedProductSelectBuilder->build($productId, $storeId)) . ')'
);

$this->linkedProductMap[$key] = $this->collectionFactory->create()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ protected function setUp()
public function testBuild()
{
$productId = 42;
$storeId = 1;

/** @var Select|\PHPUnit_Framework_MockObject_MockObject $selectMock */
$selectMock = $this->getMockBuilder(Select::class)
Expand All @@ -67,6 +68,6 @@ public function testBuild()
->method('process')
->with($selectMock);

$this->assertEquals($expectedResult, $this->subject->build($productId));
$this->assertEquals($expectedResult, $this->subject->build($productId, $storeId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

namespace Magento\ConfigurableProduct\Test\Unit\Pricing\Price;

use Magento\Catalog\Model\Product;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Catalog\Api\Data\ProductInterface;
use Magento\Catalog\Model\ResourceModel\Product\LinkedProductSelectBuilderInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Api\Data\StoreInterface;
Expand Down Expand Up @@ -102,9 +102,11 @@ protected function setUp()
public function testGetProducts()
{
$productId = 1;
$storeId = 1;
$linkedProducts = ['some', 'linked', 'products', 'dataobjects'];
$product = $this->getMockBuilder(ProductInterface::class)->disableOriginalConstructor()->getMock();
$product = $this->createMock(Product::class);
$product->expects($this->any())->method('getId')->willReturn($productId);
$product->expects($this->any())->method('getStoreId')->willReturn($storeId);
$this->linkedProductSelectBuilder->expects($this->any())->method('build')->with($productId)->willReturn([]);
$this->productCollection
->expects($this->once())
Expand Down
17 changes: 4 additions & 13 deletions app/code/Magento/ProductAlert/Block/Email/AbstractEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@
namespace Magento\ProductAlert\Block\Email;

use Magento\Framework\Pricing\PriceCurrencyInterface;
use Magento\Framework\App\ObjectManager;
use Magento\ProductAlert\Block\Product\ImageProvider;

/**
* Product Alert Abstract Email Block
Expand Down Expand Up @@ -43,32 +41,23 @@ abstract class AbstractEmail extends \Magento\Framework\View\Element\Template
*/
protected $imageBuilder;

/**
* @var ImageProvider
*/
private $imageProvider;

/**
* @param \Magento\Framework\View\Element\Template\Context $context
* @param \Magento\Framework\Filter\Input\MaliciousCode $maliciousCode
* @param PriceCurrencyInterface $priceCurrency
* @param \Magento\Catalog\Block\Product\ImageBuilder $imageBuilder
* @param array $data
* @param ImageProvider $imageProvider
*/
public function __construct(
\Magento\Framework\View\Element\Template\Context $context,
\Magento\Framework\Filter\Input\MaliciousCode $maliciousCode,
PriceCurrencyInterface $priceCurrency,
\Magento\Catalog\Block\Product\ImageBuilder $imageBuilder,
array $data = [],
ImageProvider $imageProvider = null
array $data = []
) {
$this->imageBuilder = $imageBuilder;
$this->priceCurrency = $priceCurrency;
$this->_maliciousCode = $maliciousCode;
$this->imageProvider = $imageProvider ?: ObjectManager::getInstance()->get(ImageProvider::class);

parent::__construct($context, $data);
}

Expand Down Expand Up @@ -173,6 +162,8 @@ protected function _getUrlParams()
}

/**
* Get Price Render
*
* @return \Magento\Framework\Pricing\Render
*/
protected function getPriceRender()
Expand Down Expand Up @@ -227,6 +218,6 @@ public function getProductPriceHtml(
*/
public function getImage($product, $imageId, $attributes = [])
{
return $this->imageProvider->getImage($product, $imageId, $attributes);
return $this->imageBuilder->create($product, $imageId, $attributes);
}
}
Loading

0 comments on commit e6e6725

Please sign in to comment.