Skip to content

Commit

Permalink
Merge pull request #890 from magento-south/BUGS
Browse files Browse the repository at this point in the history
[SOUTH] Bugs:
- MAGETWO-64643 Product Image Import - Incorrect Position
- MAGETWO-64716 Product name ignores HTML tags and displays plain text
- MAGETWO-59821 Gift card totals are not displaying correctly
- MAGETWO-63200 State field is not required on checkout even though it is configured to be
  • Loading branch information
slavvka authored Mar 10, 2017
2 parents c7e2e11 + 90b5f97 commit eda4577
Show file tree
Hide file tree
Showing 13 changed files with 129 additions and 38 deletions.
29 changes: 29 additions & 0 deletions app/code/Magento/Catalog/Setup/UpgradeData.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ public function __construct(CategorySetupFactory $categorySetupFactory, EavSetup
/**
* {@inheritdoc}
* @SuppressWarnings(PHPMD.ExcessiveMethodLength)
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
* @SuppressWarnings(PHPMD.NPathComplexity)
*/
public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
Expand Down Expand Up @@ -360,9 +362,36 @@ public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface
$this->changePriceAttributeDefaultScope($categorySetup);
}

if (version_compare($context->getVersion(), '2.1.5') < 0) {
$this->dissallowUsingHtmlForProductName($setup);
}

$setup->endSetup();
}

/**
* Set to 'No' 'Is Allowed Html on Store Front' option on product name attribute, because product name
* is multi entity field (used in order, quote) and cannot be conditionally escaped in all places
*
* @param ModuleDataSetupInterface $categorySetup
* @return void
*/
private function dissallowUsingHtmlForProductName(ModuleDataSetupInterface $setup)
{
/** @var CategorySetup $categorySetup */
$categorySetup = $this->categorySetupFactory->create(['setup' => $setup]);
$entityTypeId = $categorySetup->getEntityTypeId(\Magento\Catalog\Model\Product::ENTITY);
$attribute = $categorySetup->getAttribute($entityTypeId, 'name');

$setup->getConnection()
->update(
$setup->getTable('catalog_eav_attribute'),
['is_html_allowed_on_front' => 0],
$setup->getConnection()->quoteInto('attribute_id = ?', $attribute['attribute_id'])
);

}

/**
* @param \Magento\Catalog\Setup\CategorySetup $categorySetup
* @return void
Expand Down
3 changes: 3 additions & 0 deletions app/code/Magento/Catalog/etc/eav_attributes.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@
<attribute code="price_type">
<field code="is_searchable" locked="true" />
</attribute>
<attribute code="name">
<field code="is_html_allowed_on_front" locked="true"/>
</attribute>
<attribute code="category_ids">
<field code="is_global" locked="true" />
<field code="is_searchable" locked="true" />
Expand Down
2 changes: 1 addition & 1 deletion app/code/Magento/Catalog/etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="Magento_Catalog" setup_version="2.1.4">
<module name="Magento_Catalog" setup_version="2.1.5">
<sequence>
<module name="Magento_Eav"/>
<module name="Magento_Cms"/>
Expand Down
23 changes: 16 additions & 7 deletions app/code/Magento/CatalogImportExport/Model/Import/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,12 @@ class Product extends \Magento\ImportExport\Model\Import\Entity\AbstractEntity
/**
* Column names that holds images files names
*
* Note: the order of array items has a value in order to properly set 'position' value
* of media gallery items.
*
* @var string[]
*/
protected $_imagesArrayKeys = ['_media_image', 'image', 'small_image', 'thumbnail', 'swatch_image'];
protected $_imagesArrayKeys = ['image', 'small_image', 'thumbnail', 'swatch_image', '_media_image'];

/**
* Permanent entity columns.
Expand Down Expand Up @@ -1627,8 +1630,14 @@ protected function _saveProducts()
);
}
$rowData[self::COL_MEDIA_IMAGE] = [];

/*
* Note: to avoid problems with undefined sorting, the value of media gallery items positions
* must be unique in scope of one product.
*/
$position = 0;
foreach ($rowImages as $column => $columnImages) {
foreach ($columnImages as $position => $columnImage) {
foreach ($columnImages as $columnImageKey => $columnImage) {
if (!isset($uploadedImages[$columnImage])) {
$uploadedFile = $this->uploadMediaFiles($columnImage, true);
if ($uploadedFile) {
Expand All @@ -1652,11 +1661,11 @@ protected function _saveProducts()

if ($uploadedFile && !isset($mediaGallery[$rowSku][$uploadedFile])) {
if (isset($existingImages[$rowSku][$uploadedFile])) {
if (isset($rowLabels[$column][$position])
&& $rowLabels[$column][$position] != $existingImages[$rowSku][$uploadedFile]['label']
if (isset($rowLabels[$column][$columnImageKey])
&& $rowLabels[$column][$columnImageKey] != $existingImages[$rowSku][$uploadedFile]['label']
) {
$labelsForUpdate[] = [
'label' => $rowLabels[$column][$position],
'label' => $rowLabels[$column][$columnImageKey],
'imageData' => $existingImages[$rowSku][$uploadedFile]
];
}
Expand All @@ -1666,8 +1675,8 @@ protected function _saveProducts()
}
$mediaGallery[$rowSku][$uploadedFile] = [
'attribute_id' => $this->getMediaGalleryAttributeId(),
'label' => isset($rowLabels[$column][$position]) ? $rowLabels[$column][$position] : '',
'position' => $position + 1,
'label' => isset($rowLabels[$column][$columnImageKey]) ? $rowLabels[$column][$columnImageKey] : '',
'position' => ++$position,
'disabled' => isset($disabledImages[$columnImage]) ? '1' : '0',
'value' => $uploadedFile,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ define([
*/
afterSubmit: function () {
window.location.href = url.build('checkout/cart/updatePost') +
'?form_key=' + window.giftOptionsConfig.giftMessage.formKey +
'?form_key=' + window.checkoutConfig.formKey +
'&cart[]';
},

Expand Down
9 changes: 9 additions & 0 deletions app/code/Magento/Ui/view/base/web/js/form/element/region.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ define([
update: function (value) {
var country = registry.get(this.parentName + '.' + 'country_id'),
options = country.indexedOptions,
isRegionRequired,
option;

if (!value) {
Expand All @@ -43,6 +44,14 @@ define([
this.validation['required-entry'] = true;
}

if (option && !this.options().length) {
registry.get(this.customName, function (input) {
isRegionRequired = !!option['is_region_required'];
input.validation['required-entry'] = isRegionRequired;
input.required(isRegionRequired);
});
}

this.required(!!option['is_region_required']);
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<constraint name="Magento\User\Test\Constraint\AssertUserSuccessLogin" />
</variation>
<variation name="UpdateAdminUserRoleEntityTestVariation2">
<data name="issue" xsi:type="string">MAGETWO-65658: [FT] User with restricted access can't log in to Admin in UpdateAdminUserEntityTest</data>
<data name="user/dataset" xsi:type="string">default</data>
<data name="role/data/resource_access" xsi:type="string">Custom</data>
<data name="role/data/roles_resources" xsi:type="string">Sales</data>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -562,6 +562,8 @@ protected function getOptionValues(\Magento\Catalog\Model\Product\Option $option
}

/**
* Test that product import with images works properly
*
* @magentoDataIsolation enabled
* @magentoDataFixture mediaImportImageFixture
* @magentoAppIsolation enabled
Expand All @@ -570,40 +572,48 @@ protected function getOptionValues(\Magento\Catalog\Model\Product\Option $option
public function testSaveMediaImage()
{
$this->importDataForMediaTest('import_media.csv');

$product = $this->getProductBySku('simple_new');

$this->assertEquals('/m/a/magento_image.jpg', $product->getData('image'));
$this->assertEquals('/m/a/magento_small_image.jpg', $product->getData('small_image'));
$this->assertEquals('/m/a/magento_thumbnail.jpg', $product->getData('thumbnail'));
$this->assertEquals('/m/a/magento_image.jpg', $product->getData('swatch_image'));

$gallery = $product->getMediaGalleryImages();
$this->assertInstanceOf(\Magento\Framework\Data\Collection::class, $gallery);
$items = $gallery->getItems();
$this->assertCount(1, $items);
$item = array_pop($items);
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $item);
$this->assertEquals('/m/a/magento_image.jpg', $item->getFile());
$this->assertEquals('Image Label', $item->getLabel());
}

/**
* Test that image labels updates after import
*
* @magentoDataFixture mediaImportImageFixture
* @magentoDataFixture Magento/Catalog/_files/product_with_image.php
*/
public function testUpdateImageLabel()
{
$this->importDataForMediaTest('import_media_update_label.csv');
$product = $this->getProductBySku('simple');

$gallery = $product->getMediaGalleryImages();
$items = $gallery->getItems();
$this->assertCount(1, $items);
$item = array_pop($items);
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $item);
$this->assertEquals('Updated Image Label', $item->getLabel());
$this->assertCount(5, $items);

$imageItem = array_shift($items);
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $imageItem);
$this->assertEquals('/m/a/magento_image.jpg', $imageItem->getFile());
$this->assertEquals('Image Label', $imageItem->getLabel());

$smallImageItem = array_shift($items);
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $smallImageItem);
$this->assertEquals('/m/a/magento_small_image.jpg', $smallImageItem->getFile());
$this->assertEquals('Small Image Label', $smallImageItem->getLabel());

$thumbnailItem = array_shift($items);
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $thumbnailItem);
$this->assertEquals('/m/a/magento_thumbnail.jpg', $thumbnailItem->getFile());
$this->assertEquals('Thumbnail Label', $thumbnailItem->getLabel());

$additionalImageOneItem = array_shift($items);
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $additionalImageOneItem);
$this->assertEquals('/m/a/magento_additional_image_one.jpg', $additionalImageOneItem->getFile());
$this->assertEquals('Additional Image Label One', $additionalImageOneItem->getLabel());

$additionalImageTwoItem = array_shift($items);
$this->assertInstanceOf(\Magento\Framework\DataObject::class, $additionalImageTwoItem);
$this->assertEquals('/m/a/magento_additional_image_two.jpg', $additionalImageTwoItem->getFile());
$this->assertEquals('Additional Image Label Two', $additionalImageTwoItem->getLabel());
}

/**
* Copy a fixture image into media import directory
* Copy fixture images into media import directory
*/
public static function mediaImportImageFixture()
{
Expand All @@ -613,9 +623,36 @@ public static function mediaImportImageFixture()
)->getDirectoryWrite(
DirectoryList::MEDIA
);

$mediaDirectory->create('import');
$dirPath = $mediaDirectory->getAbsolutePath('import');
copy(__DIR__ . '/../../../../Magento/Catalog/_files/magento_image.jpg', "{$dirPath}/magento_image.jpg");

$items = [
[
'source' => __DIR__ . '/../../../../Magento/Catalog/_files/magento_image.jpg',
'dest' => $dirPath . '/magento_image.jpg',
],
[
'source' => __DIR__ . '/../../../../Magento/Catalog/_files/magento_small_image.jpg',
'dest' => $dirPath . '/magento_small_image.jpg',
],
[
'source' => __DIR__ . '/../../../../Magento/Catalog/_files/magento_thumbnail.jpg',
'dest' => $dirPath . '/magento_thumbnail.jpg',
],
[
'source' => __DIR__ . '/_files/magento_additional_image_one.jpg',
'dest' => $dirPath . '/magento_additional_image_one.jpg',
],
[
'source' => __DIR__ . '/_files/magento_additional_image_two.jpg',
'dest' => $dirPath . '/magento_additional_image_two.jpg',
],
];

foreach ($items as $item) {
copy($item['source'], $item['dest']);
}
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
sku,store_view_code,attribute_set_code,product_type,categories,product_websites,name,description,short_description,weight,product_online,tax_class_name,visibility,price,special_price,special_price_from_date,special_price_to_date,url_key,meta_title,meta_keywords,meta_description,base_image,base_image_label,small_image,small_image_label,thumbnail_image,thumbnail_image_label,swatch_image,swatch_image_label1,created_at,updated_at,new_from_date,new_to_date,display_product_options_in,map_price,msrp_price,map_enabled,gift_message_available,custom_design,custom_design_from,custom_design_to,custom_layout_update,page_layout,product_options_container,msrp_display_actual_price_type,country_of_manufacture,additional_attributes,qty,out_of_stock_qty,use_config_min_qty,is_qty_decimal,allow_backorders,use_config_backorders,min_cart_qty,use_config_min_sale_qty,max_cart_qty,use_config_max_sale_qty,is_in_stock,notify_on_stock_below,use_config_notify_stock_qty,manage_stock,use_config_manage_stock,use_config_qty_increments,qty_increments,use_config_enable_qty_inc,enable_qty_increments,is_decimal_divided,website_id,related_skus,crosssell_skus,upsell_skus,additional_images,additional_image_labels,hide_from_product_page,custom_options,bundle_price_type,bundle_sku_type,bundle_price_view,bundle_weight_type,bundle_values,associated_skus
simple_new,,Default,simple,,base,New Product,,,,1,Taxable Goods,"Catalog, Search",10,,,,new-product,New Product,New Product,New Product ,magento_image.jpg,,magento_image.jpg,,magento_image.jpg,,magento_image.jpg,,10/20/15 07:05,10/20/15 07:05,,,Block after Info Column,,,,,,,,,,,,,"has_options=1,quantity_and_stock_status=In Stock,required_options=1",100,0,1,0,0,1,1,1,10000,1,1,1,1,1,0,1,1,0,0,0,1,,,,magento_image.jpg,Image Label,,,,,,,,
simple_new,,Default,simple,,base,New Product,,,,1,Taxable Goods,"Catalog, Search",10,,,,new-product,New Product,New Product,New Product ,magento_image.jpg,Image Label,magento_small_image.jpg,Small Image Label,magento_thumbnail.jpg,Thumbnail Label,magento_image.jpg,Image Label,10/20/15 07:05,10/20/15 07:05,,,Block after Info Column,,,,,,,,,,,,,"has_options=1,quantity_and_stock_status=In Stock,required_options=1",100,0,1,0,0,1,1,1,10000,1,1,1,1,1,0,1,1,0,0,0,1,,,,"magento_additional_image_one.jpg, magento_additional_image_two.jpg","Additional Image Label One,Additional Image Label Two",,,,,,,,

This file was deleted.

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
7 changes: 6 additions & 1 deletion lib/web/mage/adminhtml/form.js
Original file line number Diff line number Diff line change
Expand Up @@ -488,8 +488,13 @@ define([

if (isAnInputOrSelect && !isInheritCheckboxChecked) {
if (target) {
target.disabled = false;
if (target.getAttribute('readonly')) {
target.disabled = true;
} else {
target.disabled = false;
}
}

jQuery('#' + idTo).removeClass('ignore-validate');
}
}
Expand Down

0 comments on commit eda4577

Please sign in to comment.