Skip to content

Commit

Permalink
Merge pull request #411 from magento-nord/NORD-PR
Browse files Browse the repository at this point in the history
NORD-PR#7
  • Loading branch information
kandy authored Sep 22, 2016
2 parents fd12fa9 + e0d240f commit 4bb5467
Show file tree
Hide file tree
Showing 8 changed files with 136 additions and 12 deletions.
6 changes: 3 additions & 3 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -2274,7 +2274,7 @@ public function getIdentities()
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
}
}

if (($this->getOrigData('status') != $this->getData('status')) || $this->isStockStatusChanged()) {
foreach ($this->getCategoryIds() as $categoryId) {
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
Expand All @@ -2289,7 +2289,7 @@ public function getIdentities()

/**
* Check whether stock status changed
*
*
* @return bool
*/
private function isStockStatusChanged()
Expand All @@ -2307,7 +2307,7 @@ private function isStockStatusChanged()
&& ($stockItem->getIsInStock() != $stockData['is_in_stock'])
);
}

/**
* Reload PriceInfo object
*
Expand Down
24 changes: 22 additions & 2 deletions app/code/Magento/CatalogWidget/Block/Product/ProductsList.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,11 @@
* See COPYING.txt for license details.
*/

// @codingStandardsIgnoreFile

namespace Magento\CatalogWidget\Block\Product;

use Magento\Framework\DataObject\IdentityInterface;
use Magento\Widget\Block\BlockInterface;
use Magento\Framework\Pricing\PriceCurrencyInterface;

/**
* Catalog Products List widget block
Expand Down Expand Up @@ -81,6 +80,11 @@ class ProductsList extends \Magento\Catalog\Block\Product\AbstractProduct implem
*/
protected $conditionsHelper;

/**
* @var PriceCurrencyInterface
*/
private $priceCurrency;

/**
* @param \Magento\Catalog\Block\Product\Context $context
* @param \Magento\Catalog\Model\ResourceModel\Product\CollectionFactory $productCollectionFactory
Expand Down Expand Up @@ -144,6 +148,7 @@ public function getCacheKeyInfo()

return [
'CATALOG_PRODUCTS_LIST_WIDGET',
$this->getPriceCurrency()->getCurrencySymbol(),
$this->_storeManager->getStore()->getId(),
$this->_design->getDesignTheme()->getId(),
$this->httpContext->getValue(\Magento\Customer\Model\Context::CONTEXT_GROUP),
Expand Down Expand Up @@ -351,4 +356,19 @@ public function getTitle()
{
return $this->getData('title');
}

/**
* @return PriceCurrencyInterface
*
* @deprecated
*/
private function getPriceCurrency()
{
if ($this->priceCurrency === null) {
$this->priceCurrency = \Magento\Framework\App\ObjectManager::getInstance()
->get(PriceCurrencyInterface::class);
}
return $this->priceCurrency;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Magento\Framework\TestFramework\Unit\Helper\ObjectManager as ObjectManagerHelper;
use Magento\Catalog\Model\Product\Visibility;
use Magento\Framework\Pricing\PriceCurrencyInterface;

/**
* Class ProductsListTest
Expand Down Expand Up @@ -72,6 +73,11 @@ class ProductsListTest extends \PHPUnit_Framework_TestCase
*/
protected $layout;

/**
* @var PriceCurrencyInterface|\PHPUnit_Framework_MockObject_MockObject
*/
private $priceCurrency;

protected function setUp()
{
$this->collectionFactory =
Expand Down Expand Up @@ -105,11 +111,13 @@ protected function setUp()
);
$this->request = $arguments['context']->getRequest();
$this->layout = $arguments['context']->getLayout();
$this->priceCurrency = $this->getMock(PriceCurrencyInterface::class);

$this->productsList = $objectManagerHelper->getObject(
\Magento\CatalogWidget\Block\Product\ProductsList::class,
$arguments
);
$objectManagerHelper->setBackwardCompatibleProperty($this->productsList, 'priceCurrency', $this->priceCurrency);
}

public function testGetCacheKeyInfo()
Expand All @@ -130,9 +138,11 @@ public function testGetCacheKeyInfo()
$this->request->expects($this->once())->method('getParam')->with('page_number')->willReturn(1);

$this->request->expects($this->once())->method('getParams')->willReturn('request_params');
$this->priceCurrency->expects($this->once())->method('getCurrencySymbol')->willReturn('$');

$cacheKey = [
'CATALOG_PRODUCTS_LIST_WIDGET',
'$',
1,
'blank',
'context_group',
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/ConfigurableProduct/Model/LinkManagement.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ public function addChild($sku, $childSku)
}

$childrenIds[] = $child->getId();
$product->setAssociatedProductIds($childrenIds);
$product->getExtensionAttributes()->setConfigurableProductLinks($childrenIds);
$product->save();
return true;
}
Expand Down Expand Up @@ -132,7 +132,7 @@ public function removeChild($sku, $childSku)
if (count($options) == count($ids)) {
throw new NoSuchEntityException(__('Requested option doesn\'t exist'));
}
$product->addData(['associated_product_ids' => $ids]);
$product->getExtensionAttributes()->setConfigurableProductLinks($ids);
$product->save();
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
namespace Magento\ConfigurableProduct\Test\Unit\Model;

use Magento\ConfigurableProduct\Model\Product\Type\Configurable;
use Magento\ConfigurableProduct\Test\Unit\Model\Product\ProductExtensionAttributes;

/**
* @SuppressWarnings(PHPMD.CouplingBetweenObjects)
Expand Down Expand Up @@ -162,7 +163,15 @@ public function testAddChild()
->will(
$this->returnValue([0 => [1, 2, 3]])
);
$configurable->expects($this->once())->method('__call')->with('setAssociatedProductIds', [[1, 2, 3, 999]]);

$extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class)
->setMethods(['setConfigurableProductLinks'])
->disableOriginalConstructor()
->getMockForAbstractClass();

$configurable->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes);
$extensionAttributes->expects($this->once())->method('setConfigurableProductLinks')->willReturnSelf();

$configurable->expects($this->once())->method('save');

$this->assertTrue(true, $this->object->addChild($productSku, $childSku));
Expand Down Expand Up @@ -206,7 +215,7 @@ public function testRemoveChild()
$childSku = 'simple_10';

$product = $this->getMockBuilder(\Magento\Catalog\Model\Product::class)
->setMethods(['getTypeInstance', 'save', 'getTypeId', 'addData', '__wakeup'])
->setMethods(['getTypeInstance', 'save', 'getTypeId', 'addData', '__wakeup', 'getExtensionAttributes'])
->disableOriginalConstructor()
->getMock();

Expand Down Expand Up @@ -234,7 +243,14 @@ public function testRemoveChild()
$productType->expects($this->once())->method('getUsedProducts')
->will($this->returnValue([$option]));

$product->expects($this->once())->method('addData')->with(['associated_product_ids' => []]);
$extensionAttributes = $this->getMockBuilder(ProductExtensionAttributes::class)
->setMethods(['setConfigurableProductLinks'])
->disableOriginalConstructor()
->getMockForAbstractClass();

$product->expects($this->once())->method('getExtensionAttributes')->willReturn($extensionAttributes);
$extensionAttributes->expects($this->once())->method('setConfigurableProductLinks')->willReturnSelf();

$product->expects($this->once())->method('save');
$this->assertTrue($this->object->removeChild($productSku, $childSku));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ protected function prepareVariations()
'sku' => $product->getSku(),
'name' => $product->getName(),
'qty' => $this->getProductStockQty($product),
'price' => $currency->toCurrency(sprintf("%f", $price), ['display' => false]),
'price' => $price,
'price_string' => $currency->toCurrency(sprintf("%f", $price)),
'price_currency' => $this->locator->getStore()->getBaseCurrency()->getCurrencySymbol(),
'configurable_attribute' => $this->getJsonConfigurableAttributes($variationOptions),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -432,7 +432,7 @@ define([

for (t = 0; t < thumbs.length; t++) {
this._setThumbsIcon(thumbs.eq(t), t);
this._checkForVideo(e, fotorama, t);
this._checkForVideo(e, fotorama, t + 1);
}

this.fotoramaItem.on('fotorama:showend', $.proxy(function (evt, fotoramaData) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
<?php
/**
* Copyright © 2016 Magento. All rights reserved.
* See COPYING.txt for license details.
*/
namespace Magento\ConfigurableProduct\Ui\DataProvider\Product\Form\Modifier\Data;

class AssociatedProductsTest extends \PHPUnit_Framework_TestCase
{
/**
* @var \Magento\Framework\ObjectManagerInterface $objectManager
*/
private $objectManager;

/**
* @var \Magento\Framework\Registry $registry
*/
private $registry;

public function setUp()
{
$this->objectManager = \Magento\TestFramework\Helper\Bootstrap::getObjectManager();
$this->registry = $this->objectManager->get(\Magento\Framework\Registry::class);

}

/**
* @dataProvider getProductMatrixDataProvider
* @param string $interfaceLocale
* @magentoDataFixture Magento/ConfigurableProduct/_files/product_configurable.php
* @magentoAppArea adminhtml
*/
public function testGetProductMatrix($interfaceLocale)
{
$productSku = 'configurable';
$associatedProductsData = [
[10 => '10.000'],
[20 => '20.000']
];
/** @var \Magento\Catalog\Api\ProductRepositoryInterface $productRepository */
$productRepository = $this->objectManager->create(\Magento\Catalog\Api\ProductRepositoryInterface::class);
$this->registry->register('current_product', $productRepository->get($productSku));
/** @var $store \Magento\Store\Model\Store */
$store = $this->objectManager->create(\Magento\Store\Model\Store::class);
$store->load('admin');
$this->registry->register('current_store', $store);
/** @var \Magento\Framework\Locale\ResolverInterface|\PHPUnit_Framework_MockObject_MockObject $localeResolver */
$localeResolver = $this->getMockBuilder(\Magento\Framework\Locale\ResolverInterface::class)
->setMethods(['getLocale'])
->getMockForAbstractClass();
$localeResolver->expects($this->any())->method('getLocale')->willReturn($interfaceLocale);
$localeCurrency = $this->objectManager->create(
\Magento\Framework\Locale\CurrencyInterface::class,
['localeResolver' => $localeResolver]
);
$associatedProducts = $this->objectManager->create(
AssociatedProducts::class,
['localeCurrency' => $localeCurrency]
);
foreach ($associatedProducts->getProductMatrix() as $productMatrixId => $productMatrixData) {
$this->assertEquals(
$associatedProductsData[$productMatrixId][$productMatrixData['id']],
$productMatrixData['price']
);
}
}

/**
* @return array
*/
public function getProductMatrixDataProvider()
{
return [
['en_US'],
['zh_Hans_CN']
];
}
}

0 comments on commit 4bb5467

Please sign in to comment.