Skip to content

Commit

Permalink
MAGETWO-72254: Backport PR-9713 for Magento 2.1 - stringify cookie va…
Browse files Browse the repository at this point in the history
…lue to fix #5596 #10749

 - Merge Pull Request #10749 from hostep/magento2:backport-pr-9713
 - Merged commits:
   1. dc79eb7
   2. 7a611cc
  • Loading branch information
ishakhsuvarov committed Sep 4, 2017
2 parents a386178 + 7a611cc commit f200327
Show file tree
Hide file tree
Showing 911 changed files with 137,492 additions and 47,501 deletions.
108 changes: 108 additions & 0 deletions CHANGELOG.md

Large diffs are not rendered by default.

5 changes: 5 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,8 @@ If you are a new GitHub user, we recommend that you create your own [free github
3. Create and test your work.
4. Fork the Magento 2 repository according to [Fork a repository instructions](http://devdocs.magento.com/guides/v2.0/contributor-guide/contributing.html#fork) and when you are ready to send us a pull request – follow [Create a pull request instructions](http://devdocs.magento.com/guides/v2.0/contributor-guide/contributing.html#pull_request).
5. Once your contribution is received, Magento 2 development team will review the contribution and collaborate with you as needed to improve the quality of the contribution.

## Code of Conduct

Please note that this project is released with a Contributor Code of Conduct. We expect you to agree to its terms when participating in this project.
The full text is available in the repository [Wiki](https://github.com/magento/magento2/wiki/Magento-Code-of-Conduct).
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
2 changes: 1 addition & 1 deletion app/code/Magento/AdvancedPricingImportExport/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"magento/framework": "100.1.*"
},
"type": "magento2-module",
"version": "100.1.2",
"version": "100.1.3",
"license": [
"OSL-3.0",
"AFL-3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
<item name="componentType" xsi:type="string">dynamicRows</item>
<item name="recordTemplate" xsi:type="string">record</item>
<item name="deleteButtonLabel" xsi:type="string">Remove</item>
<item name="addButtonLabel" xsi:type="string">Add New User Agent Rule</item>
<item name="addButtonLabel" xsi:type="string" translate="true">Add New User Agent Rule</item>
<item name="deleteProperty" xsi:type="boolean">false</item>
<item name="dndConfig" xsi:type="array">
<item name="enabled" xsi:type="boolean">false</item>
Expand All @@ -67,7 +67,7 @@
<item name="dataType" xsi:type="string">text</item>
<item name="dataScope" xsi:type="string">search</item>
<item name="fit" xsi:type="boolean">false</item>
<item name="label" xsi:type="string">Search String</item>
<item name="label" xsi:type="string" translate="true">Search String</item>
<item name="showFallbackReset" xsi:type="boolean">false</item>
</item>
</argument>
Expand All @@ -80,7 +80,7 @@
<item name="dataType" xsi:type="string">text</item>
<item name="dataScope" xsi:type="string">value</item>
<item name="fit" xsi:type="boolean">false</item>
<item name="label" xsi:type="string">Theme Name</item>
<item name="label" xsi:type="string" translate="true">Theme Name</item>
<item name="showFallbackReset" xsi:type="boolean">false</item>
</item>
</argument>
Expand All @@ -91,7 +91,7 @@
<item name="componentType" xsi:type="string">actionDelete</item>
<item name="dataType" xsi:type="string">text</item>
<item name="fit" xsi:type="boolean">false</item>
<item name="label" xsi:type="string">Actions</item>
<item name="label" xsi:type="string" translate="true">Actions</item>
<item name="sortOrder" xsi:type="string">50</item>
<item name="additionalClasses" xsi:type="string">data-grid-actions-cell</item>
<item name="template" xsi:type="string">Magento_Backend/dynamic-rows/cells/action-delete</item>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,12 @@
use Magento\Backend\Block\Widget\Form;
use Magento\Backend\Block\Widget\Form\Generic;

/**
* Class Content
*
* @deprecated
* @see \Magento\Catalog\Ui\DataProvider\Product\Form\Modifier\Eav
*/
class Content extends Generic
{
/**
Expand Down
5 changes: 5 additions & 0 deletions app/code/Magento/Catalog/Block/Product/View/Attributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
use Magento\Framework\Phrase;
use Magento\Framework\Pricing\PriceCurrencyInterface;

/**
* Product attributes block.
*/
class Attributes extends \Magento\Framework\View\Element\Template
{
/**
Expand Down Expand Up @@ -59,6 +62,7 @@ public function getProduct()
if (!$this->_product) {
$this->_product = $this->_coreRegistry->registry('product');
}

return $this->_product;
}

Expand Down Expand Up @@ -96,6 +100,7 @@ public function getAdditionalData(array $excludeAttr = [])
}
}
}

return $data;
}
}
28 changes: 20 additions & 8 deletions app/code/Magento/Catalog/Controller/Adminhtml/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ abstract class Category extends \Magento\Backend\App\Action
*/
protected function _initCategory($getRootInstead = false)
{
$categoryId = (int)$this->getRequest()->getParam('id', false);
$categoryId = $this->resolveCategoryId();
$storeId = (int)$this->getRequest()->getParam('store');
$category = $this->_objectManager->create('Magento\Catalog\Model\Category');
$category = $this->_objectManager->create(\Magento\Catalog\Model\Category::class);
$category->setStoreId($storeId);

if ($categoryId) {
$category->load($categoryId);
if ($storeId) {
$rootId = $this->_objectManager->get(
'Magento\Store\Model\StoreManagerInterface'
\Magento\Store\Model\StoreManagerInterface::class
)->getStore(
$storeId
)->getRootCategoryId();
Expand All @@ -55,13 +55,25 @@ protected function _initCategory($getRootInstead = false)
}
}

$this->_objectManager->get('Magento\Framework\Registry')->register('category', $category);
$this->_objectManager->get('Magento\Framework\Registry')->register('current_category', $category);
$this->_objectManager->get('Magento\Cms\Model\Wysiwyg\Config')
$this->_objectManager->get(\Magento\Framework\Registry::class)->register('category', $category);
$this->_objectManager->get(\Magento\Framework\Registry::class)->register('current_category', $category);
$this->_objectManager->get(\Magento\Cms\Model\Wysiwyg\Config::class)
->setStoreId($this->getRequest()->getParam('store'));
return $category;
}

/**
* Resolve Category Id (from get or from post).
*
* @return int
*/
private function resolveCategoryId()
{
$categoryId = (int)$this->getRequest()->getParam('id', false);

return $categoryId ?: (int)$this->getRequest()->getParam('entity_id', false);
}

/**
* Build response for ajax request
*
Expand All @@ -79,7 +91,7 @@ protected function ajaxRequestResponse($category, $resultPage)
if (empty($breadcrumbsPath)) {
// but if no category, and it is deleted - prepare breadcrumbs from path, saved in session
$breadcrumbsPath = $this->_objectManager->get(
'Magento\Backend\Model\Auth\Session'
\Magento\Backend\Model\Auth\Session::class
)->getDeletedPath(
true
);
Expand Down Expand Up @@ -107,7 +119,7 @@ protected function ajaxRequestResponse($category, $resultPage)
['response' => $eventResponse, 'controller' => $this]
);
/** @var \Magento\Framework\Controller\Result\Json $resultJson */
$resultJson = $this->_objectManager->get('Magento\Framework\Controller\Result\Json');
$resultJson = $this->_objectManager->get(\Magento\Framework\Controller\Result\Json::class);
$resultJson->setHeader('Content-type', 'application/json', true);
$resultJson->setData($eventResponse->getData());
return $resultJson;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,15 @@ protected function _isAllowed()
}

/**
* Upload file controller action
* Upload file controller action.
*
* @return \Magento\Framework\Controller\ResultInterface
*/
public function execute()
{
$imageId = $this->_request->getParam('param_name', 'image');
try {
$result = $this->imageUploader->saveFileToTmpDir('image');
$result = $this->imageUploader->saveFileToTmpDir($imageId);

$result['cookie'] = [
'name' => $this->_getSession()->getName(),
Expand Down
66 changes: 59 additions & 7 deletions app/code/Magento/Catalog/Controller/Adminhtml/Category/Save.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
namespace Magento\Catalog\Controller\Adminhtml\Category;

use Magento\Store\Model\StoreManagerInterface;
use Magento\Catalog\Api\Data\CategoryAttributeInterface;

/**
* Class Save
Expand Down Expand Up @@ -48,6 +49,13 @@ class Save extends \Magento\Catalog\Controller\Adminhtml\Category
*/
private $storeManager;

/**
* Config instance holder.
*
* @var \Magento\Eav\Model\Config
*/
private $eavConfig;

/**
* Constructor
*
Expand All @@ -72,8 +80,9 @@ public function __construct(
}

/**
* Filter category data
* Filter category data.
*
* @deprecated
* @param array $rawData
* @return array
*/
Expand Down Expand Up @@ -126,7 +135,7 @@ public function execute()
$this->storeManager->setCurrentStore($store->getCode());
$parentId = isset($categoryPostData['parent']) ? $categoryPostData['parent'] : null;
if ($categoryPostData) {
$category->addData($this->_filterCategoryPostData($categoryPostData));
$category->addData($categoryPostData);
if ($isNewCategory) {
$parentCategory = $this->getParentCategory($parentId, $storeId);
$category->setPath($parentCategory->getPath());
Expand Down Expand Up @@ -248,21 +257,48 @@ public function execute()
}

/**
* Image data preprocessing
* Sets image attribute data to false, if image was removed.
*
* @param array $data
*
* @return array
*/
public function imagePreprocessing($data)
public function imagePreprocessing(array $data)
{
if (empty($data['image'])) {
unset($data['image']);
$data['image']['delete'] = true;
$emptyImageAttributes = $this->getEmptyImageAttributes($data);
$attributeCodes = array_keys($emptyImageAttributes);
foreach ($attributeCodes as $attributeCode) {
$data[$attributeCode] = false;
}

return $data;
}

/**
* Get image attributes without value.
*
* @param array $data
* @return array
*/
private function getEmptyImageAttributes(array $data)
{
$result = [];
$entityType = $this->getConfig()->getEntityType(CategoryAttributeInterface::ENTITY_TYPE_CODE);
foreach ($entityType->getAttributeCollection() as $attribute) {
$attributeCode = $attribute->getAttributeCode();
$backendModel = $attribute->getBackend();
if (isset($data[$attributeCode])) {
continue;
}
if (!$backendModel instanceof \Magento\Catalog\Model\Category\Attribute\Backend\Image) {
continue;
}
$result[$attributeCode] = $attribute;
}

return $result;
}

/**
* Converting inputs from string to boolean
*
Expand Down Expand Up @@ -346,4 +382,20 @@ protected function getRedirectParams($isNewCategory, $hasError, $categoryId, $pa
}
return ['path' => $path, 'params' => $params];
}

/**
* Get Config instance.
*
* @return \Magento\Eav\Model\Config
*/
private function getConfig()
{
if (null === $this->eavConfig) {
$this->eavConfig = \Magento\Framework\App\ObjectManager::getInstance()->get(
\Magento\Eav\Model\Config::class
);
}

return $this->eavConfig;
}
}
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
Loading

0 comments on commit f200327

Please sign in to comment.