Skip to content

Commit

Permalink
Merge pull request #3115 from magento-honey-badgers/MAGETWO-91439-Pri…
Browse files Browse the repository at this point in the history
…ce-prices-disappearing-on-category-page-remove-resolver

[honey] MAGETWO-91439: Prices disappearing when product is assigned to a different store and default store is disabled
  • Loading branch information
cpartica authored Sep 17, 2018
2 parents 22a2e2c + e861d64 commit ca42048
Show file tree
Hide file tree
Showing 39 changed files with 959 additions and 501 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

/**
* Interface BaseSelectProcessorInterface
*
* @api
* @since 101.0.3
*/
Expand All @@ -20,6 +21,8 @@ interface BaseSelectProcessorInterface
const PRODUCT_TABLE_ALIAS = 'child';

/**
* Process the select statement
*
* @param Select $select
* @return Select
* @since 101.0.3
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class StatusBaseSelectProcessor
Expand All @@ -30,28 +31,32 @@ class StatusBaseSelectProcessor implements BaseSelectProcessorInterface
private $metadataPool;

/**
* @var StoreResolverInterface
* @var StoreManagerInterface
*/
private $storeResolver;
private $storeManager;

/**
* @param Config $eavConfig
* @param MetadataPool $metadataPool
* @param StoreResolverInterface $storeResolver
* @param StoreManagerInterface $storeManager
*
* @SuppressWarnings(PHPMD.UnusedFormalParameter)
*/
public function __construct(
Config $eavConfig,
MetadataPool $metadataPool,
StoreResolverInterface $storeResolver
StoreResolverInterface $storeResolver,
StoreManagerInterface $storeManager = null
) {
$this->eavConfig = $eavConfig;
$this->metadataPool = $metadataPool;
$this->storeResolver = $storeResolver;
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(StoreManagerInterface::class);
}

/**
* @param Select $select
* @return Select
* @inheritdoc
*/
public function process(Select $select)
{
Expand All @@ -70,7 +75,7 @@ public function process(Select $select)
['status_attr' => $statusAttribute->getBackendTable()],
"status_attr.{$linkField} = " . self::PRODUCT_TABLE_ALIAS . ".{$linkField}"
. ' AND status_attr.attribute_id = ' . (int)$statusAttribute->getAttributeId()
. ' AND status_attr.store_id = ' . $this->storeResolver->getCurrentStoreId(),
. ' AND status_attr.store_id = ' . $this->storeManager->getStore()->getId(),
[]
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
use Magento\Framework\EntityManager\EntityMetadataInterface;
use Magento\Framework\EntityManager\MetadataPool;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Store\Model\Store;

/**
Expand All @@ -35,9 +35,9 @@ class StatusBaseSelectProcessorTest extends \PHPUnit\Framework\TestCase
private $metadataPool;

/**
* @var StoreResolverInterface|\PHPUnit_Framework_MockObject_MockObject
* @var StoreManagerInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $storeResolver;
private $storeManager;

/**
* @var Select|\PHPUnit_Framework_MockObject_MockObject
Expand All @@ -53,13 +53,13 @@ protected function setUp()
{
$this->eavConfig = $this->getMockBuilder(Config::class)->disableOriginalConstructor()->getMock();
$this->metadataPool = $this->getMockBuilder(MetadataPool::class)->disableOriginalConstructor()->getMock();
$this->storeResolver = $this->getMockBuilder(StoreResolverInterface::class)->getMock();
$this->storeManager = $this->getMockBuilder(StoreManagerInterface::class)->getMock();
$this->select = $this->getMockBuilder(Select::class)->disableOriginalConstructor()->getMock();

$this->statusBaseSelectProcessor = (new ObjectManager($this))->getObject(StatusBaseSelectProcessor::class, [
'eavConfig' => $this->eavConfig,
'metadataPool' => $this->metadataPool,
'storeResolver' => $this->storeResolver,
'storeManager' => $this->storeManager,
]);
}

Expand Down Expand Up @@ -94,8 +94,14 @@ public function testProcess()
->with(Product::ENTITY, ProductInterface::STATUS)
->willReturn($statusAttribute);

$this->storeResolver->expects($this->once())
->method('getCurrentStoreId')
$storeMock = $this->getMockBuilder(\Magento\Store\Api\Data\StoreInterface::class)->getMock();

$this->storeManager->expects($this->once())
->method('getStore')
->willReturn($storeMock);

$storeMock->expects($this->once())
->method('getId')
->willReturn($currentStoreId);

$this->select->expects($this->at(0))
Expand Down
94 changes: 28 additions & 66 deletions app/code/Magento/Checkout/Block/Checkout/LayoutProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

use Magento\Checkout\Helper\Data;
use Magento\Framework\App\ObjectManager;
use Magento\Store\Api\StoreResolverInterface;
use Magento\Store\Model\StoreManagerInterface;

/**
* Class LayoutProcessor
Expand Down Expand Up @@ -40,9 +40,9 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso
private $checkoutDataHelper;

/**
* @var StoreResolverInterface
* @var StoreManagerInterface
*/
private $storeResolver;
private $storeManager;

/**
* @var \Magento\Shipping\Model\Config
Expand All @@ -53,30 +53,36 @@ class LayoutProcessor implements \Magento\Checkout\Block\Checkout\LayoutProcesso
* @param \Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider
* @param \Magento\Ui\Component\Form\AttributeMapper $attributeMapper
* @param AttributeMerger $merger
* @param \Magento\Customer\Model\Options|null $options
* @param Data|null $checkoutDataHelper
* @param \Magento\Shipping\Model\Config|null $shippingConfig
* @param StoreManagerInterface|null $storeManager
*/
public function __construct(
\Magento\Customer\Model\AttributeMetadataDataProvider $attributeMetadataDataProvider,
\Magento\Ui\Component\Form\AttributeMapper $attributeMapper,
AttributeMerger $merger
AttributeMerger $merger,
\Magento\Customer\Model\Options $options = null,
Data $checkoutDataHelper = null,
\Magento\Shipping\Model\Config $shippingConfig = null,
StoreManagerInterface $storeManager = null
) {
$this->attributeMetadataDataProvider = $attributeMetadataDataProvider;
$this->attributeMapper = $attributeMapper;
$this->merger = $merger;
$this->options = $options ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Customer\Model\Options::class);
$this->checkoutDataHelper = $checkoutDataHelper ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(Data::class);
$this->shippingConfig = $shippingConfig ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(\Magento\Shipping\Model\Config::class);
$this->storeManager = $storeManager ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(StoreManagerInterface::class);
}

/**
* @deprecated 100.0.11
* @return \Magento\Customer\Model\Options
*/
private function getOptions()
{
if (!is_object($this->options)) {
$this->options = ObjectManager::getInstance()->get(\Magento\Customer\Model\Options::class);
}
return $this->options;
}

/**
* Get address attributes.
*
* @return array
*/
private function getAddressAttributes()
Expand Down Expand Up @@ -143,8 +149,8 @@ private function convertElementsToSelect($elements, $attributesToConvert)
public function process($jsLayout)
{
$attributesToConvert = [
'prefix' => [$this->getOptions(), 'getNamePrefixOptions'],
'suffix' => [$this->getOptions(), 'getNameSuffixOptions'],
'prefix' => [$this->options, 'getNamePrefixOptions'],
'suffix' => [$this->options, 'getNameSuffixOptions'],
];

$elements = $this->getAddressAttributes();
Expand Down Expand Up @@ -192,8 +198,8 @@ public function process($jsLayout)
*/
private function processShippingChildrenComponents($shippingRatesLayout)
{
$activeCarriers = $this->getShippingConfig()->getActiveCarriers(
$this->getStoreResolver()->getCurrentStoreId()
$activeCarriers = $this->shippingConfig->getActiveCarriers(
$this->storeManager->getStore()->getId()
);
foreach (array_keys($shippingRatesLayout) as $carrierName) {
$carrierKey = str_replace('-rates-validation', '', $carrierName);
Expand All @@ -206,6 +212,7 @@ private function processShippingChildrenComponents($shippingRatesLayout)

/**
* Appends billing address form component to payment layout
*
* @param array $paymentLayout
* @param array $elements
* @return array
Expand All @@ -221,7 +228,7 @@ private function processPaymentChildrenComponents(array $paymentLayout, array $e
}

// The if billing address should be displayed on Payment method or page
if ($this->getCheckoutDataHelper()->isDisplayBillingOnPaymentMethodAvailable()) {
if ($this->checkoutDataHelper->isDisplayBillingOnPaymentMethodAvailable()) {
$paymentLayout['payments-list']['children'] =
array_merge_recursive(
$paymentLayout['payments-list']['children'],
Expand Down Expand Up @@ -340,49 +347,4 @@ private function getBillingAddressComponent($paymentCode, $elements)
],
];
}

/**
* Get checkout data helper instance
*
* @return Data
* @deprecated 100.1.4
*/
private function getCheckoutDataHelper()
{
if (!$this->checkoutDataHelper) {
$this->checkoutDataHelper = ObjectManager::getInstance()->get(Data::class);
}

return $this->checkoutDataHelper;
}

/**
* Retrieve Shipping Configuration.
*
* @return \Magento\Shipping\Model\Config
* @deprecated 100.2.0
*/
private function getShippingConfig()
{
if (!$this->shippingConfig) {
$this->shippingConfig = ObjectManager::getInstance()->get(\Magento\Shipping\Model\Config::class);
}

return $this->shippingConfig;
}

/**
* Get store resolver.
*
* @return StoreResolverInterface
* @deprecated 100.2.0
*/
private function getStoreResolver()
{
if (!$this->storeResolver) {
$this->storeResolver = ObjectManager::getInstance()->get(StoreResolverInterface::class);
}

return $this->storeResolver;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,12 @@
use Magento\Checkout\Helper\Data;
use Magento\Customer\Model\AttributeMetadataDataProvider;
use Magento\Customer\Model\Options;
use Magento\Framework\TestFramework\Unit\Helper\ObjectManager;

use Magento\Ui\Component\Form\AttributeMapper;
use PHPUnit_Framework_MockObject_MockObject as MockObject;

/**
* LayoutProcessorTest covers a list of variations for
* checkout layout processor
*
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
* LayoutProcessorTest covers a list of variations for checkout layout processor
*/
class LayoutProcessorTest extends \PHPUnit\Framework\TestCase
{
Expand Down Expand Up @@ -50,12 +47,10 @@ class LayoutProcessorTest extends \PHPUnit\Framework\TestCase
/**
* @var MockObject
*/
private $storeResolver;
private $storeManager;

protected function setUp()
{
$objectManager = new ObjectManager($this);

$this->attributeDataProvider = $this->getMockBuilder(AttributeMetadataDataProvider::class)
->disableOriginalConstructor()
->setMethods(['loadAttributesCollection'])
Expand All @@ -80,17 +75,21 @@ protected function setUp()
->disableOriginalConstructor()
->getMock();

$shippingConfig = $this->getMockBuilder(\Magento\Shipping\Model\Config::class)
->disableOriginalConstructor()
->getMock();

$this->storeManager = $this->createMock(\Magento\Store\Model\StoreManagerInterface::class);

$this->layoutProcessor = new LayoutProcessor(
$this->attributeDataProvider,
$this->attributeMapper,
$this->attributeMerger
$this->attributeMerger,
$options,
$this->dataHelper,
$shippingConfig,
$this->storeManager
);

$this->storeResolver = $this->createMock(\Magento\Store\Api\StoreResolverInterface::class);

$objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'checkoutDataHelper', $this->dataHelper);
$objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'options', $options);
$objectManager->setBackwardCompatibleProperty($this->layoutProcessor, 'storeResolver', $this->storeResolver);
}

/**
Expand Down Expand Up @@ -277,7 +276,7 @@ private function getBillingComponent($paymentCode)
'telephone' => [
'config' => [
'tooltip' => [
'description' => __('For delivery questions.'),
'description' => ('For delivery questions.'),
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
*/
namespace Magento\Cms\Block\Adminhtml\Page\Grid\Renderer\Action;

use Magento\Store\Api\StoreResolverInterface;

/**
* Url builder class used to compose dynamic urls.
*/
class UrlBuilder
{
/**
Expand Down Expand Up @@ -38,7 +39,7 @@ public function getUrl($routePath, $scope, $store)
[
'_current' => false,
'_nosid' => true,
'_query' => [StoreResolverInterface::PARAM_NAME => $store]
'_query' => [\Magento\Store\Model\StoreManagerInterface::PARAM_NAME => $store]
]
);

Expand Down
Loading

0 comments on commit ca42048

Please sign in to comment.