Skip to content

Commit

Permalink
Merge pull request #594 from magento-falcons/MAGETWO-60931
Browse files Browse the repository at this point in the history
Bugs
- MAGETWO-60067 Advanced Pricing is very slow to import
- MAGETWO-60165 Inability to Run the DI Compiler before setup
- MAGETWO-48516 Most of category fields don't have Use Default Value option in Store/StoreView scope on the redesigned category page
MAGETWO-60630 Wrong dependency version for magento/module-catalog
MAGETWO-56675 Multiple plugins cannot be run in setup area
  • Loading branch information
VladimirZaets committed Nov 15, 2016
2 parents 5ffafe2 + 651da5a commit 1759088
Show file tree
Hide file tree
Showing 13 changed files with 309 additions and 74 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -542,19 +542,24 @@ protected function retrieveOldSkus()
*/
protected function processCountExistingPrices($prices, $table)
{
$oldSkus = $this->retrieveOldSkus();
$existProductIds = array_intersect_key($oldSkus, $prices);
if (!count($existProductIds)) {
return $this;
}

$tableName = $this->_resourceFactory->create()->getTable($table);
$productEntityLinkField = $this->getProductEntityLinkField();
$existingPrices = $this->_connection->fetchAssoc(
$this->_connection->select()->from(
$tableName,
['value_id', $productEntityLinkField, 'all_groups', 'customer_group_id']
)
)->where($productEntityLinkField . ' IN (?)', $existProductIds)
);
$oldSkus = $this->retrieveOldSkus();
foreach ($existingPrices as $existingPrice) {
foreach ($oldSkus as $sku => $productId) {
if ($existingPrice[$productEntityLinkField] == $productId && isset($prices[$sku])) {
$this->incrementCounterUpdated($prices[$sku], $existingPrice);
foreach ($prices as $sku => $skuPrices) {
if (isset($oldSkus[$sku]) && $existingPrice[$productEntityLinkField] == $oldSkus[$sku]) {
$this->incrementCounterUpdated($skuPrices, $existingPrice);
}
}
}
Expand Down
145 changes: 133 additions & 12 deletions app/code/Magento/Catalog/Model/Category/DataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@
*/
namespace Magento\Catalog\Model\Category;

use Magento\Catalog\Api\Data\CategoryInterface;
use Magento\Catalog\Api\Data\EavAttributeInterface;
use Magento\Catalog\Model\Attribute\ScopeOverriddenValue;
use Magento\Catalog\Model\Category;
use Magento\Catalog\Model\ResourceModel\Eav\Attribute as EavAttribute;
use Magento\Eav\Api\Data\AttributeInterface;
use Magento\Eav\Model\Config;
use Magento\Eav\Model\Entity\Type;
use Magento\Catalog\Model\ResourceModel\Category\CollectionFactory as CategoryCollectionFactory;
use Magento\Framework\Stdlib\ArrayManager;
use Magento\Store\Model\Store;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Ui\Component\Form\Field;
Expand Down Expand Up @@ -112,6 +116,16 @@ class DataProvider extends \Magento\Ui\DataProvider\AbstractDataProvider
*/
private $categoryFactory;

/**
* @var ScopeOverriddenValue
*/
private $scopeOverriddenValue;

/**
* @var ArrayManager
*/
private $arrayManager;

/**
* DataProvider constructor
*
Expand Down Expand Up @@ -151,8 +165,91 @@ public function __construct(
$this->storeManager = $storeManager;
$this->request = $request;
$this->categoryFactory = $categoryFactory;

parent::__construct($name, $primaryFieldName, $requestFieldName, $meta, $data);
$this->meta = $this->prepareMeta($this->meta);
}

/**
* @inheritdoc
*/
public function getMeta()
{
$meta = parent::getMeta();
$meta = $this->prepareMeta($meta);

$category = $this->getCurrentCategory();

if ($category) {
$meta = $this->addUseDefaultValueCheckbox($category, $meta);
$meta = $this->resolveParentInheritance($category, $meta);
}

return $meta;
}

/**
* @param Category $category
* @param array $meta
* @return array
*/
private function addUseDefaultValueCheckbox(Category $category, array $meta)
{
/** @var EavAttributeInterface $attribute */
foreach ($category->getAttributes() as $attribute) {
$attributeCode = $attribute->getAttributeCode();
$canDisplayUseDefault = $attribute->getScope() != EavAttributeInterface::SCOPE_GLOBAL_TEXT
&& $category->getId()
&& $category->getStoreId();
$attributePath = $this->getArrayManager()->findPath($attributeCode, $meta);

if (
!$attributePath
|| !$canDisplayUseDefault
|| in_array($attributeCode, $this->elementsWithUseConfigSetting)
) {
continue;
}

$meta = $this->getArrayManager()->merge(
[$attributePath, 'arguments/data/config'],
$meta,
[
'service' => [
'template' => 'ui/form/element/helper/service',
],
'disabled' => !$this->getScopeOverriddenValue()->containsValue(
CategoryInterface::class,
$category,
$attributeCode,
$this->request->getParam($this->requestScopeFieldName, Store::DEFAULT_STORE_ID)
)
]
);
}

return $meta;
}

/**
* Removes not necessary inheritance fields
*
* @param Category $category
* @param array $meta
* @return array
*/
private function resolveParentInheritance(Category $category, array $meta)
{
if (!$category->getParentId() || !$this->getArrayManager()->findPath('custom_use_parent_settings', $meta)) {
return $meta;
}

$meta = $this->getArrayManager()->merge(
[$this->getArrayManager()->findPath('custom_use_parent_settings', $meta), 'arguments/data/config'],
$meta,
['visible' => false]
);

return $meta;
}

/**
Expand Down Expand Up @@ -204,7 +301,6 @@ public function getData()
$category = $this->getCurrentCategory();
if ($category) {
$categoryData = $category->getData();
$categoryData = $this->addUseDefaultSettings($category, $categoryData);
$categoryData = $this->addUseConfigSettings($categoryData);
$categoryData = $this->filterFields($categoryData);
$categoryData = $this->convertValues($category, $categoryData);
Expand Down Expand Up @@ -292,6 +388,7 @@ protected function addUseConfigSettings($categoryData)
* @param \Magento\Catalog\Model\Category $category
* @param array $categoryData
* @return array
* @deprecated
*/
protected function addUseDefaultSettings($category, $categoryData)
{
Expand Down Expand Up @@ -406,15 +503,6 @@ public function getDefaultMetaData($result)
$result['use_config.available_sort_by']['default'] = true;
$result['use_config.default_sort_by']['default'] = true;
$result['use_config.filter_price_range']['default'] = true;
if ($this->request->getParam('store') && $this->request->getParam('id')) {
$result['use_default.url_key']['checked'] = true;
$result['use_default.url_key']['default'] = true;
$result['use_default.url_key']['visible'] = true;
} else {
$result['use_default.url_key']['checked'] = false;
$result['use_default.url_key']['default'] = false;
$result['use_default.url_key']['visible'] = false;
}

return $result;
}
Expand Down Expand Up @@ -454,7 +542,6 @@ protected function getFieldsMap()
[
'url_key',
'url_key_create_redirect',
'use_default.url_key',
'url_key_group',
'meta_title',
'meta_keywords',
Expand Down Expand Up @@ -484,4 +571,38 @@ protected function getFieldsMap()
],
];
}

/**
* Retrieve scope overridden value
*
* @return ScopeOverriddenValue
* @deprecated
*/
private function getScopeOverriddenValue()
{
if (null === $this->scopeOverriddenValue) {
$this->scopeOverriddenValue = \Magento\Framework\App\ObjectManager::getInstance()->get(
ScopeOverriddenValue::class
);
}

return $this->scopeOverriddenValue;
}

/**
* Retrieve array manager
*
* @return ArrayManager
* @deprecated
*/
private function getArrayManager()
{
if (null === $this->arrayManager) {
$this->arrayManager = \Magento\Framework\App\ObjectManager::getInstance()->get(
ArrayManager::class
);
}

return $this->arrayManager;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -375,19 +375,6 @@
<item name="source" xsi:type="string">category</item>
<item name="label" xsi:type="string" translate="true">URL Key</item>
<item name="sortOrder" xsi:type="number">10</item>
<item name="imports" xsi:type="array">
<item name="disabled" xsi:type="string">${ $.provider }:data.use_default.url_key</item>
</item>
</item>
</argument>
</field>
<field name="use_default.url_key">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="description" xsi:type="string" translate="true">Use Default</item>
<item name="dataType" xsi:type="string">boolean</item>
<item name="formElement" xsi:type="string">checkbox</item>
<item name="sortOrder" xsi:type="number">20</item>
</item>
</argument>
</field>
Expand Down Expand Up @@ -453,17 +440,18 @@
<field name="custom_use_parent_settings">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="additionalClasses" xsi:type="string">admin__field-no-label</item>
<item name="additionalClasses" xsi:type="string">admin__field-x-small</item>
<item name="sortOrder" xsi:type="number">170</item>
<item name="label" xsi:type="string"/>
<item name="description" xsi:type="string" translate="true">Use Parent Category Settings</item>
<item name="label" xsi:type="string">Use Parent Category Settings</item>
<item name="dataType" xsi:type="string">boolean</item>
<item name="formElement" xsi:type="string">checkbox</item>
<item name="valueMap" xsi:type="array">
<item name="true" xsi:type="string">1</item>
<item name="false" xsi:type="string">0</item>
</item>
<item name="default" xsi:type="string">0</item>
<item name="component" xsi:type="string">Magento_Ui/js/form/element/single-checkbox</item>
<item name="prefer" xsi:type="string">toggle</item>
</item>
</argument>
</field>
Expand Down Expand Up @@ -509,20 +497,21 @@
<field name="custom_apply_to_products">
<argument name="data" xsi:type="array">
<item name="config" xsi:type="array">
<item name="additionalClasses" xsi:type="string">admin__field-no-label</item>
<item name="additionalClasses" xsi:type="string">admin__field-x-small</item>
<item name="sortOrder" xsi:type="number">210</item>
<item name="label" xsi:type="string"/>
<item name="description" xsi:type="string" translate="true">Apply Design to Products</item>
<item name="label" xsi:type="string" translate="true">Apply Design to Products</item>
<item name="dataType" xsi:type="string">boolean</item>
<item name="formElement" xsi:type="string">checkbox</item>
<item name="imports" xsi:type="array">
<item name="disabled" xsi:type="string">ns = ${ $.ns }, index = custom_use_parent_settings :checked</item>
</item>
<item name="valueMap" xsi:type="array">
<item name="true" xsi:type="string">1</item>
<item name="false" xsi:type="string">0</item>
</item>
<item name="default" xsi:type="string">0</item>
<item name="component" xsi:type="string">Magento_Ui/js/form/element/single-checkbox</item>
<item name="prefer" xsi:type="string">toggle</item>
<item name="imports" xsi:type="array">
<item name="disabled" xsi:type="string">ns = ${ $.ns }, index = custom_use_parent_settings:checked</item>
</item>
</item>
</argument>
</field>
Expand Down
23 changes: 18 additions & 5 deletions app/code/Magento/Developer/Model/Logger/Handler/Debug.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
use Magento\Framework\App\State;
use Magento\Framework\Filesystem\DriverInterface;
use Magento\Store\Model\ScopeInterface;
use Magento\Framework\App\DeploymentConfig;

/**
* Class Debug
Expand All @@ -25,32 +26,44 @@ class Debug extends \Magento\Framework\Logger\Handler\Debug
*/
private $scopeConfig;

/**
* @var DeploymentConfig
*/
private $deploymentConfig;

/**
* @param DriverInterface $filesystem
* @param State $state
* @param ScopeConfigInterface $scopeConfig
* @param DeploymentConfig $deploymentConfig
* @param string $filePath
*/
public function __construct(
DriverInterface $filesystem,
State $state,
ScopeConfigInterface $scopeConfig,
DeploymentConfig $deploymentConfig,
$filePath = null
) {
parent::__construct($filesystem, $filePath);

$this->state = $state;
$this->scopeConfig = $scopeConfig;
$this->deploymentConfig = $deploymentConfig;
}

/**
* {@inheritdoc}
*/
public function isHandling(array $record)
{
return
parent::isHandling($record)
&& $this->state->getMode() !== State::MODE_PRODUCTION
&& $this->scopeConfig->getValue('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE);
if ($this->deploymentConfig->isAvailable()) {
return
parent::isHandling($record)
&& $this->state->getMode() !== State::MODE_PRODUCTION
&& $this->scopeConfig->getValue('dev/debug/debug_logging', ScopeInterface::SCOPE_STORE);
}

return parent::isHandling($record);
}
}
}

0 comments on commit 1759088

Please sign in to comment.