Skip to content

Commit

Permalink
Merge pull request #1664 from magento-engcom/develop-prs
Browse files Browse the repository at this point in the history
Public Pull Requests

#11961 [Backport 2.3] #11898 - Change NL PostCode Pattern by @osrecio
#11801 #6948: CatalogImportExport categoryProcessor does not support escaped delimiter by @serhii-balko
#11888 Save background color correctly in images. by @raumatbel
#11862 [Backport 2.3-develop] #11697 Theme: Added html node to page xml root, cause validation error by @adrian-martinez-interactiv4

Fixed Public Issues

#11898 Zip code Netherlands should allow zipcode without space
#6948 CatalogImportExport categoryProcessor does not support escaped delimiter
#8799 Image brackground
#11697 Theme: Added html node to page xml root, cause validation error
  • Loading branch information
Oleksii Korshenko committed Nov 4, 2017
2 parents 097f016 + eadd5dc commit 927a6e2
Show file tree
Hide file tree
Showing 11 changed files with 92 additions and 15 deletions.
11 changes: 8 additions & 3 deletions app/code/Magento/Catalog/Model/ImageExtractor.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
*/
namespace Magento\Catalog\Model;

use Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter;
use Magento\Catalog\Helper\Image;
use Magento\Catalog\Model\Product\Attribute\Backend\Media\ImageEntryConverter;
use Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface;

class ImageExtractor implements \Magento\Framework\View\Xsd\Media\TypeDataExtractorInterface
class ImageExtractor implements TypeDataExtractorInterface
{
/**
* Extract configuration data of images from the DOM structure
Expand All @@ -30,8 +31,11 @@ public function process(\DOMElement $mediaNode, $mediaParentTag)
if ($attribute->nodeType != XML_ELEMENT_NODE) {
continue;
}
if ($attribute->tagName == 'background') {
$attributeTagName = $attribute->tagName;
if ($attributeTagName === 'background') {
$nodeValue = $this->processImageBackground($attribute->nodeValue);
} elseif ($attributeTagName === 'width' || $attributeTagName === 'height') {
$nodeValue = intval($attribute->nodeValue);
} else {
$nodeValue = $attribute->nodeValue;
}
Expand All @@ -55,6 +59,7 @@ private function processImageBackground($backgroundString)
$backgroundArray = [];
if (preg_match($pattern, $backgroundString, $backgroundArray)) {
array_shift($backgroundArray);
$backgroundArray = array_map('intval', $backgroundArray);
}
return $backgroundArray;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ protected function setUp()
public function testProcess()
{
$expectedArray = include(__DIR__ . '/_files/converted_view.php');
$this->assertEquals($expectedArray, $this->model->process($this->getDomElement(), 'media'));
$this->assertSame($expectedArray, $this->model->process($this->getDomElement(), 'media'));
}

/**
Expand Down
21 changes: 19 additions & 2 deletions app/code/Magento/CatalogImportExport/Model/Export/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
*/
namespace Magento\CatalogImportExport\Model\Export;

use Magento\CatalogImportExport\Model\Import\Product\CategoryProcessor;
use Magento\ImportExport\Model\Import;
use \Magento\Store\Model\Store;
use \Magento\CatalogImportExport\Model\Import\Product as ImportProduct;
Expand Down Expand Up @@ -438,11 +439,12 @@ protected function initCategories()
if ($pathSize > 1) {
$path = [];
for ($i = 1; $i < $pathSize; $i++) {
$path[] = $collection->getItemById($structure[$i])->getName();
$name = $collection->getItemById($structure[$i])->getName();
$path[] = $this->quoteCategoryDelimiter($name);
}
$this->_rootCategories[$category->getId()] = array_shift($path);
if ($pathSize > 2) {
$this->_categories[$category->getId()] = implode('/', $path);
$this->_categories[$category->getId()] = implode(CategoryProcessor::DELIMITER_CATEGORY, $path);
}
}
}
Expand Down Expand Up @@ -1470,4 +1472,19 @@ protected function getProductEntityLinkField()
}
return $this->productEntityLinkField;
}

/**
* Quoting category delimiter character in string.
*
* @param string $string
* @return string
*/
private function quoteCategoryDelimiter($string)
{
return str_replace(
CategoryProcessor::DELIMITER_CATEGORY,
'\\' . CategoryProcessor::DELIMITER_CATEGORY,
$string
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,8 @@ protected function initCategories()
if ($pathSize > 1) {
$path = [];
for ($i = 1; $i < $pathSize; $i++) {
$path[] = $collection->getItemById((int)$structure[$i])->getName();
$name = $collection->getItemById((int)$structure[$i])->getName();
$path[] = $this->quoteDelimiter($name);
}
/** @var string $index */
$index = $this->standardizeString(
Expand Down Expand Up @@ -114,7 +115,7 @@ protected function createCategory($name, $parentId)
}
$category->setPath($parentCategory->getPath());
$category->setParentId($parentId);
$category->setName($name);
$category->setName($this->unquoteDelimiter($name));
$category->setIsActive(true);
$category->setIncludeInMenu(true);
$category->setAttributeSetId($category->getDefaultAttributeSetId());
Expand All @@ -137,7 +138,7 @@ protected function upsertCategory($categoryPath)
$index = $this->standardizeString($categoryPath);

if (!isset($this->categories[$index])) {
$pathParts = explode(self::DELIMITER_CATEGORY, $categoryPath);
$pathParts = preg_split('~(?<!\\\)' . preg_quote(self::DELIMITER_CATEGORY, '~') . '~', $categoryPath);
$parentId = \Magento\Catalog\Model\Category::TREE_ROOT_ID;
$path = '';

Expand Down Expand Up @@ -243,4 +244,26 @@ private function standardizeString($string)
{
return mb_strtolower($string);
}

/**
* Quoting delimiter character in string.
*
* @param string $string
* @return string
*/
private function quoteDelimiter($string)
{
return str_replace(self::DELIMITER_CATEGORY, '\\' . self::DELIMITER_CATEGORY, $string);
}

/**
* Remove quoting delimiter in string.
*
* @param string $string
* @return string
*/
private function unquoteDelimiter($string)
{
return str_replace('\\' . self::DELIMITER_CATEGORY, self::DELIMITER_CATEGORY, $string);
}
}
2 changes: 1 addition & 1 deletion app/code/Magento/Directory/etc/zip_codes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@
</zip>
<zip countryCode="NL">
<codes>
<code id="pattern_1" active="true" example="1234 AB">^[0-9]{4}\s?[a-zA-Z]{2}$</code>
<code id="pattern_1" active="true" example="1234 AB/1234AB">^[1-9][0-9]{3}\s?[a-zA-Z]{2}$</code>
</codes>
</zip>
<zip countryCode="NO">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php
/**
* Copyright © Magento, Inc. All rights reserved.
* See COPYING.txt for license details.
*/

$category = \Magento\TestFramework\Helper\Bootstrap::getObjectManager()->create(\Magento\Catalog\Model\Category::class);
$category->isObjectNew(true);
$category->setId(
3331
)->setCreatedAt(
'2017-06-23 09:50:07'
)->setName(
'Category with slash/ symbol'
)->setParentId(
2
)->setPath(
'1/2/3331'
)->setLevel(
2
)->setAvailableSortBy(
['position', 'name']
)->setDefaultSortBy(
'name'
)->setIsActive(
true
)->setPosition(
1
)->save();
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ public function testExportSpecialChars()
);
$exportData = $this->model->export();
$this->assertContains('simple ""1""', $exportData);
$this->assertContains('Category with slash\/ symbol', $exportData);
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sku,product_type,store_view_code,name,price,attribute_set_code,categories,product_websites
simple1,simple,,"simple 2",25,Default,"Default Category/Category 1|Default Category/Category 2",base
simple1,simple,,"simple 2",25,Default,"Default Category/Category 1|Default Category/Category\/ 2",base
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sku,product_type,store_view_code,name,price,attribute_set_code,categories,product_websites,url_key
simple1,simple,,"simple 1",25,Default,"Default Category/Category 1,Default Category/Category 2",base,simple1-ds
simple1,simple,,"simple 1",25,Default,"Default Category/Category 1,Default Category/Category\/ 2",base,simple1-ds
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
*/
/** Create category */
require dirname(dirname(__DIR__)) . '/Catalog/_files/category.php';
/** Create category with special chars */
require dirname(dirname(__DIR__)) . '/Catalog/_files/catalog_category_with_slash.php';
/** Create fixture store */
require dirname(dirname(__DIR__)) . '/Store/_files/second_store.php';
/** Create product with multiselect attribute and values */
Expand All @@ -28,10 +30,8 @@
->setVisibility(\Magento\Catalog\Model\Product\Visibility::VISIBILITY_BOTH)
->setStatus(\Magento\Catalog\Model\Product\Attribute\Source\Status::STATUS_ENABLED)
->setWebsiteIds([1])
->setCateroryIds([])
->setStockData(['qty' => 100, 'is_in_stock' => 1])
->setCanSaveCustomOptions(true)
->setCategoryIds([333])
->setUpSellLinkData([$product->getId() => ['position' => 1]]);
->setCategoryIds([333, 3331]);

$productModel->setOptions([])->save();
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/elements.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/head.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/body.xsd"/>
<xs:include schemaLocation="urn:magento:framework:View/Layout/etc/html.xsd"/>

<xs:element name="layout">
<xs:annotation>
Expand Down Expand Up @@ -45,6 +46,7 @@
<xs:element ref="referenceBlock" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="body" type="bodyType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="head" type="headType" minOccurs="0" maxOccurs="unbounded"/>
<xs:element name="html" type="htmlType" minOccurs="0" maxOccurs="unbounded"/>
</xs:choice>
</xs:complexType>

Expand Down

0 comments on commit 927a6e2

Please sign in to comment.