Skip to content

Commit

Permalink
Merge pull request #81 from magento-nord/develop
Browse files Browse the repository at this point in the history
[NORD] Bugfixes
  • Loading branch information
Oleksii Korshenko committed Jun 7, 2016
2 parents 658b520 + b72a3bb commit cf694a2
Show file tree
Hide file tree
Showing 28 changed files with 447 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class CustomOptionProcessor implements CartItemProcessorInterface
/** @var CustomOptionFactory */
protected $customOptionFactory;

/** @var \Magento\Catalog\Model\Product\Option\UrlBuilder */
private $urlBuilder;

/**
* @param DataObject\Factory $objectFactory
* @param ProductOptionFactory $productOptionFactory
Expand Down Expand Up @@ -63,7 +66,6 @@ public function convertToBuyRequest(CartItemInterface $cartItem)
return null;
}


/**
* @inheritDoc
*/
Expand Down Expand Up @@ -117,10 +119,45 @@ protected function updateOptionsValues(array &$options)
$option = $this->customOptionFactory->create();
$option->setOptionId($optionId);
if (is_array($optionValue)) {
$optionValue = $this->processFileOptionValue($optionValue);
$optionValue = implode(',', $optionValue);
}
$option->setOptionValue($optionValue);
$optionValue = $option;
}
}

/**
* Returns option value with file built URL
*
* @param array $optionValue
* @return array
*/
private function processFileOptionValue(array $optionValue)
{
if (array_key_exists('url', $optionValue) &&
array_key_exists('route', $optionValue['url']) &&
array_key_exists('params', $optionValue['url'])
) {
$optionValue['url'] = $this->getUrlBuilder()->getUrl(
$optionValue['url']['route'],
$optionValue['url']['params']
);
}
return $optionValue;
}

/**
* @return \Magento\Catalog\Model\Product\Option\UrlBuilder
*
* @deprecated
*/
private function getUrlBuilder()
{
if ($this->urlBuilder === null) {
$this->urlBuilder = \Magento\Framework\App\ObjectManager::getInstance()
->get('\Magento\Catalog\Model\Product\Option\UrlBuilder');
}
return $this->urlBuilder;
}
}
29 changes: 5 additions & 24 deletions app/code/Magento/Catalog/Model/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -302,11 +302,6 @@ class Product extends \Magento\Catalog\Model\AbstractModel implements
*/
protected $_productIdCached;

/**
* @var \Magento\Framework\App\State
*/
private $appState;

/**
* List of attributes in ProductInterface
* @var array
Expand Down Expand Up @@ -931,8 +926,10 @@ public function afterSave()

// Resize images for catalog product and save results to image cache
/** @var Product\Image\Cache $imageCache */
$imageCache = $this->imageCacheFactory->create();
$imageCache->generate($this);
if (!$this->_appState->isAreaCodeEmulated()) {
$imageCache = $this->imageCacheFactory->create();
$imageCache->generate($this);
}

return $result;
}
Expand Down Expand Up @@ -2277,7 +2274,7 @@ public function getIdentities()
$identities[] = self::CACHE_PRODUCT_CATEGORY_TAG . '_' . $categoryId;
}
}
if ($this->getAppState()->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
if ($this->_appState->getAreaCode() == \Magento\Framework\App\Area::AREA_FRONTEND) {
$identities[] = self::CACHE_TAG;
}
return array_unique($identities);
Expand Down Expand Up @@ -2566,22 +2563,6 @@ public function setId($value)
return $this->setData('entity_id', $value);
}

/**
* Get application state
*
* @deprecated
* @return \Magento\Framework\App\State
*/
private function getAppState()
{
if (!$this->appState instanceof \Magento\Framework\App\State) {
$this->appState = \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Framework\App\State::class
);
}
return $this->appState;
}

/**
* @return ProductLinkRepositoryInterface
*/
Expand Down
40 changes: 40 additions & 0 deletions app/code/Magento/Catalog/Model/ProductOptionProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ class ProductOptionProcessor implements ProductOptionProcessorInterface
*/
protected $customOptionFactory;

/**
* @var \Magento\Catalog\Model\Product\Option\UrlBuilder
*/
private $urlBuilder;

/**
* @param DataObjectFactory $objectFactory
* @param CustomOptionFactory $customOptionFactory
Expand Down Expand Up @@ -84,6 +89,7 @@ public function convertToProductOption(DataObject $request)
$data = [];
foreach ($options as $optionId => $optionValue) {
if (is_array($optionValue)) {
$optionValue = $this->processFileOptionValue($optionValue);
$optionValue = implode(',', $optionValue);
}

Expand All @@ -98,4 +104,38 @@ public function convertToProductOption(DataObject $request)

return [];
}

/**
* Returns option value with file built URL
*
* @param array $optionValue
* @return array
*/
private function processFileOptionValue(array $optionValue)
{
if (array_key_exists('url', $optionValue) &&
array_key_exists('route', $optionValue['url']) &&
array_key_exists('params', $optionValue['url'])
) {
$optionValue['url'] = $this->getUrlBuilder()->getUrl(
$optionValue['url']['route'],
$optionValue['url']['params']
);
}
return $optionValue;
}

/**
* @return \Magento\Catalog\Model\Product\Option\UrlBuilder
*
* @deprecated
*/
private function getUrlBuilder()
{
if ($this->urlBuilder === null) {
$this->urlBuilder = \Magento\Framework\App\ObjectManager::getInstance()
->get('\Magento\Catalog\Model\Product\Option\UrlBuilder');
}
return $this->urlBuilder;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,8 @@ protected function _prepareMultiselectIndex($entityIds = null, $attributeId = nu
)->where(
'pvd.attribute_id IN(?)',
$attrIds
)->where(
'cpe.entity_id IS NOT NULL'
);

$statusCond = $connection->quoteInto('=?', ProductStatus::STATUS_ENABLED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ protected function setUp()
$this->dataObjectFactory,
$this->customOptionFactory
);

$urlBuilder = $this->getMockBuilder('\Magento\Catalog\Model\Product\Option\UrlBuilder')
->disableOriginalConstructor()
->setMethods(['getUrl'])
->getMock();
$urlBuilder->expects($this->any())->method('getUrl')->willReturn('http://built.url/string/');

$reflection = new \ReflectionClass(get_class($this->processor));
$reflectionProperty = $reflection->getProperty('urlBuilder');
$reflectionProperty->setAccessible(true);
$reflectionProperty->setValue($this->processor, $urlBuilder);
}

/**
Expand Down Expand Up @@ -186,7 +197,14 @@ public function dataProviderConvertToProductOption()
[
'options' => [
1 => 'value',
2 => [1, 2],
2 => [
1,
2,
'url' => [
'route' => 'route',
'params' => ['id' => 20, 'key' => '8175c7c36ef69432347e']
]
],
],
'expected' => 'custom_options',
],
Expand Down
35 changes: 23 additions & 12 deletions app/code/Magento/Catalog/Test/Unit/Model/ProductTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -213,8 +213,14 @@ protected function setUp()
false
);

$stateMock = $this->getMock('Magento\FrameworkApp\State', ['getAreaCode'], [], '', false);
$stateMock->expects($this->any())
$this->appStateMock = $this->getMock(
'Magento\Framework\App\State',
['getAreaCode', 'isAreaCodeEmulated'],
[],
'',
false
);
$this->appStateMock->expects($this->any())
->method('getAreaCode')
->will($this->returnValue(\Magento\Backend\App\Area\FrontNameResolver::AREA_CODE));

Expand All @@ -233,7 +239,7 @@ protected function setUp()
'\Magento\Framework\Model\Context',
['getEventDispatcher', 'getCacheManager', 'getAppState', 'getActionValidator'], [], '', false
);
$contextMock->expects($this->any())->method('getAppState')->will($this->returnValue($stateMock));
$contextMock->expects($this->any())->method('getAppState')->will($this->returnValue($this->appStateMock));
$contextMock->expects($this->any())
->method('getEventDispatcher')
->will($this->returnValue($this->eventManagerMock));
Expand Down Expand Up @@ -370,15 +376,6 @@ protected function setUp()
'data' => ['id' => 1]
]
);

$this->appStateMock = $this->getMockBuilder(\Magento\Framework\App\State::class)
->disableOriginalConstructor()
->setMethods([])
->getMock();
$modelReflection = new \ReflectionClass(get_class($this->model));
$appStateReflection = $modelReflection->getProperty('appState');
$appStateReflection->setAccessible(true);
$appStateReflection->setValue($this->model, $this->appStateMock);
}

public function testGetAttributes()
Expand Down Expand Up @@ -800,6 +797,20 @@ public function testSave()
$this->model->afterSave();
}

/**
* Image cache generation would not be performed if area was emulated
*/
public function testSaveIfAreaEmulated()
{
$this->appStateMock->expects($this->any())->method('isAreaCodeEmulated')->willReturn(true);
$this->imageCache->expects($this->never())
->method('generate')
->with($this->model);
$this->configureSaveTest();
$this->model->beforeSave();
$this->model->afterSave();
}

/**
* Test for `save` method for duplicated product
*/
Expand Down
3 changes: 2 additions & 1 deletion app/code/Magento/Catalog/Ui/Component/ColumnFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class ColumnFactory
protected $jsComponentMap = [
'text' => 'Magento_Ui/js/grid/columns/column',
'select' => 'Magento_Ui/js/grid/columns/select',
'multiselect' => 'Magento_Ui/js/grid/columns/select',
'date' => 'Magento_Ui/js/grid/columns/date',
];

Expand All @@ -29,7 +30,7 @@ class ColumnFactory
'text' => 'text',
'boolean' => 'select',
'select' => 'select',
'multiselect' => 'select',
'multiselect' => 'multiselect',
'date' => 'date',
];

Expand Down
Loading

0 comments on commit cf694a2

Please sign in to comment.