Skip to content

Commit

Permalink
Merge pull request #1136 from magento-tsg/2.1.8-develop-pr15
Browse files Browse the repository at this point in the history
[TSG] Backporting for 2.1 (pr15) (2.1.8)
  • Loading branch information
Volodymyr Klymenko authored May 26, 2017
2 parents ff253a7 + 19b8f08 commit 7ea39cd
Show file tree
Hide file tree
Showing 66 changed files with 3,303 additions and 594 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function execute()
$attributeCode = $attributeCode ?: $this->generateCode($frontendLabel[0]);
$attributeId = $this->getRequest()->getParam('attribute_id');
$attribute = $this->_objectManager->create(
'Magento\Catalog\Model\ResourceModel\Eav\Attribute'
\Magento\Catalog\Model\ResourceModel\Eav\Attribute::class
)->loadByCode(
$this->_entityTypeId,
$attributeCode
Expand All @@ -87,10 +87,10 @@ public function execute()
if ($this->getRequest()->has('new_attribute_set_name')) {
$setName = $this->getRequest()->getParam('new_attribute_set_name');
/** @var $attributeSet \Magento\Eav\Model\Entity\Attribute\Set */
$attributeSet = $this->_objectManager->create('Magento\Eav\Model\Entity\Attribute\Set');
$attributeSet = $this->_objectManager->create(\Magento\Eav\Model\Entity\Attribute\Set::class);
$attributeSet->setEntityTypeId($this->_entityTypeId)->load($setName, 'attribute_set_name');
if ($attributeSet->getId()) {
$setName = $this->_objectManager->get('Magento\Framework\Escaper')->escapeHtml($setName);
$setName = $this->_objectManager->get(\Magento\Framework\Escaper::class)->escapeHtml($setName);
$this->messageManager->addError(__('An attribute set named \'%1\' already exists.', $setName));

$layout = $this->layoutFactory->create();
Expand Down Expand Up @@ -149,10 +149,16 @@ private function setMessageToResponse($response, $messages)
/**
* @param DataObject $response
* @param array|null $options
*
* @return void
*/
private function checkUniqueOption(DataObject $response, array $options = null)
{
if (is_array($options) && !$this->isUniqueAdminValues($options['value'], $options['delete'])) {
if (is_array($options)
&& !empty($options['value'])
&& !empty($options['delete'])
&& !$this->isUniqueAdminValues($options['value'], $options['delete'])
) {
$this->setMessageToResponse($response, [__('The value of Admin must be unique.')]);
$response->setError(true);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

namespace Magento\Catalog\Model\Indexer\Category\Product;

use Magento\Framework\DB\Query\Generator as QueryGenerator;
use Magento\Framework\App\ResourceConnection;
use Magento\Framework\EntityManager\MetadataPool;

Expand Down Expand Up @@ -102,20 +103,29 @@ abstract class AbstractAction
*/
protected $tempTreeIndexTableName;

/**
* @var QueryGenerator
*/
private $queryGenerator;

/**
* @param ResourceConnection $resource
* @param \Magento\Store\Model\StoreManagerInterface $storeManager
* @param \Magento\Catalog\Model\Config $config
* @param QueryGenerator $queryGenerator
*/
public function __construct(
\Magento\Framework\App\ResourceConnection $resource,
\Magento\Store\Model\StoreManagerInterface $storeManager,
\Magento\Catalog\Model\Config $config
\Magento\Catalog\Model\Config $config,
QueryGenerator $queryGenerator = null
) {
$this->resource = $resource;
$this->connection = $resource->getConnection();
$this->storeManager = $storeManager;
$this->config = $config;
$this->queryGenerator = $queryGenerator ?: \Magento\Framework\App\ObjectManager::getInstance()
->get(QueryGenerator::class);
}

/**
Expand Down Expand Up @@ -302,22 +312,35 @@ protected function isRangingNeeded()
}

/**
* Return selects cut by min and max
* Return selects cut by min and max.
*
* @param \Magento\Framework\DB\Select $select
* @param string $field
* @param int $range
* @return \Magento\Framework\DB\Select[]
*/
protected function prepareSelectsByRange(\Magento\Framework\DB\Select $select, $field, $range = self::RANGE_CATEGORY_STEP)
{
return $this->isRangingNeeded() ? $this->connection->selectsByRange(
$field,
$select,
$range
) : [
$select
];
protected function prepareSelectsByRange(
\Magento\Framework\DB\Select $select,
$field,
$range = self::RANGE_CATEGORY_STEP
) {
if ($this->isRangingNeeded()) {
$iterator = $this->queryGenerator->generate(
$field,
$select,
$range,
\Magento\Framework\DB\Query\BatchIteratorInterface::NON_UNIQUE_FIELD_ITERATOR
);

$queries = [];
foreach ($iterator as $query) {
$queries[] = $query;
}

return $queries;
}

return [$select];
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,30 @@ protected function _prepareFinalPriceData($entityIds = null)
* @param string|null $type product type, all if null
* @return $this
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function prepareFinalPriceDataForType($entityIds, $type)
{
$this->_prepareDefaultFinalPriceTable();

$select = $this->getSelect($entityIds, $type);
$query = $select->insertFromSelect($this->_getDefaultFinalPriceTable(), [], false);
$this->getConnection()->query($query);
return $this;
}

/**
* Forms Select for collecting price related data for final price index table
* Next types of prices took into account: default, special, tier price
* Moved to protected for possible reusing
*
* @param int|array $entityIds Ids for filtering output result
* @param string|null $type Type for filtering output result by specified product type (all if null)
* @return \Magento\Framework\DB\Select
* @throws \Magento\Framework\Exception\LocalizedException
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
*/
protected function getSelect($entityIds = null, $type = null)
{
$metadata = $this->getMetadataPool()->getMetadata(\Magento\Catalog\Api\Data\ProductInterface::class);
$connection = $this->getConnection();
$select = $connection->select()->from(
Expand Down Expand Up @@ -368,13 +387,10 @@ protected function prepareFinalPriceDataForType($entityIds, $type)
'select' => $select,
'entity_field' => new \Zend_Db_Expr('e.entity_id'),
'website_field' => new \Zend_Db_Expr('cw.website_id'),
'store_field' => new \Zend_Db_Expr('cs.store_id')
'store_field' => new \Zend_Db_Expr('cs.store_id'),
]
);

$query = $select->insertFromSelect($this->_getDefaultFinalPriceTable(), [], false);
$connection->query($query);
return $this;
return $select;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,16 @@ public function testUniqueValidation(array $options, $isError)
public function provideUniqueData()
{
return [
// valid options
[
'no values' => [
[
'delete' => [
"option_0" => "",
"option_1" => "",
"option_2" => "",
]
], false
],
'valid options' => [
[
'value' => [
"option_0" => [1, 0],
Expand All @@ -213,8 +221,7 @@ public function provideUniqueData()
]
], false
],
//with duplicate
[
'duplicate options' => [
[
'value' => [
"option_0" => [1, 0],
Expand All @@ -228,8 +235,7 @@ public function provideUniqueData()
]
], true
],
//with duplicate but deleted
[
'duplicate and deleted' => [
[
'value' => [
"option_0" => [1, 0],
Expand Down
1 change: 1 addition & 0 deletions app/code/Magento/Catalog/etc/eav_attributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
<field code="is_searchable" locked="true" />
</attribute>
<attribute code="category_ids">
<field code="is_global" locked="true" />
<field code="is_searchable" locked="true" />
<field code="used_for_sort_by" locked="true" />
<field code="is_used_in_grid" locked="true" />
Expand Down
4 changes: 2 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ protected function collectRawData()

if ($storeId != Store::DEFAULT_STORE_ID
&& isset($data[$itemId][Store::DEFAULT_STORE_ID][$fieldName])
&& $data[$itemId][Store::DEFAULT_STORE_ID][$fieldName] == $attrValue
&& $data[$itemId][Store::DEFAULT_STORE_ID][$fieldName] == htmlspecialchars_decode($attrValue)
) {
continue;
}
Expand Down Expand Up @@ -983,7 +983,7 @@ protected function collectRawData()
$data[$itemId][$storeId][self::COL_ATTR_SET] = $this->_attrSetIdToName[$attrSetId];
$data[$itemId][$storeId][self::COL_TYPE] = $item->getTypeId();
}
$data[$itemId][$storeId][self::COL_SKU] = $item->getSku();
$data[$itemId][$storeId][self::COL_SKU] = htmlspecialchars_decode($item->getSku());
$data[$itemId][$storeId]['store_id'] = $storeId;
$data[$itemId][$storeId]['product_id'] = $itemId;
$data[$itemId][$storeId]['product_link_id'] = $productLinkId;
Expand Down
Loading

0 comments on commit 7ea39cd

Please sign in to comment.