From 359717703c4a4aeeac67e56b018245b604a91d1a Mon Sep 17 00:00:00 2001 From: Michail Slabko Date: Fri, 30 Oct 2015 18:19:09 +0200 Subject: [PATCH 1/4] MAGETWO-39872: Unable to update "title", "type", "price", "price_type" in product options through API --- .../Model/ResourceModel/Product/Option.php | 30 +++++++++---------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php index cf7445dabfec7..a857bc63f40ac 100644 --- a/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php +++ b/app/code/Magento/Catalog/Model/ResourceModel/Product/Option.php @@ -119,23 +119,21 @@ protected function _saveValuePrices(\Magento\Framework\Model\AbstractModel $obje $optionId = $connection->fetchOne($statement); if ($optionId) { - if ($object->getStoreId() == '0') { - $data = $this->_prepareDataForTable( - new \Magento\Framework\DataObject( - ['price' => $object->getPrice(), 'price_type' => $object->getPriceType()] - ), - $priceTable - ); + $data = $this->_prepareDataForTable( + new \Magento\Framework\DataObject( + ['price' => $object->getPrice(), 'price_type' => $object->getPriceType()] + ), + $priceTable + ); - $connection->update( - $priceTable, - $data, - [ - 'option_id = ?' => $object->getId(), - 'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID - ] - ); - } + $connection->update( + $priceTable, + $data, + [ + 'option_id = ?' => $object->getId(), + 'store_id = ?' => \Magento\Store\Model\Store::DEFAULT_STORE_ID + ] + ); } else { $data = $this->_prepareDataForTable( new \Magento\Framework\DataObject( From 27cddc3e1782c06a0a9649cfb9ad41afd6678fa3 Mon Sep 17 00:00:00 2001 From: Michail Slabko Date: Mon, 2 Nov 2015 11:11:30 +0200 Subject: [PATCH 2/4] MAGETWO-43873: Swatch image type is absent --- .../Block/Adminhtml/Product/Steps/Bulk.php | 36 ++++- .../Model/Product/VariationHandler.php | 11 +- .../Product/VariationMediaAttributes.php | 54 +++++++ .../product/edit/attribute/steps/bulk.phtml | 140 +++++++----------- .../adminhtml/web/js/variations/steps/bulk.js | 25 +--- 5 files changed, 152 insertions(+), 114 deletions(-) create mode 100644 app/code/Magento/ConfigurableProduct/Model/Product/VariationMediaAttributes.php diff --git a/app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Steps/Bulk.php b/app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Steps/Bulk.php index d440b7347b6e6..0ad92cdbb636e 100644 --- a/app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Steps/Bulk.php +++ b/app/code/Magento/ConfigurableProduct/Block/Adminhtml/Product/Steps/Bulk.php @@ -12,16 +12,23 @@ class Bulk extends \Magento\Ui\Block\Component\StepsWizard\StepAbstract /** @var \Magento\Catalog\Helper\Image */ protected $image; + /** + * @var \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes + */ + protected $variationMediaAttributes; + /** * @param \Magento\Framework\View\Element\Template\Context $context * @param \Magento\Catalog\Helper\Image $image */ public function __construct( \Magento\Framework\View\Element\Template\Context $context, - \Magento\Catalog\Helper\Image $image + \Magento\Catalog\Helper\Image $image, + \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes $variationMediaAttributes ) { parent::__construct($context); $this->image = $image; + $this->variationMediaAttributes = $variationMediaAttributes; } /** @@ -39,4 +46,31 @@ public function getNoImageUrl() { return $this->image->getDefaultPlaceholderUrl('thumbnail'); } + + /** + * Get image types data + * + * @return array + */ + public function getImageTypes() + { + $imageTypes = []; + foreach ($this->variationMediaAttributes->getMediaAttributes() as $attribute) { + /* @var $attribute \Magento\Eav\Model\Entity\Attribute */ + $imageTypes[$attribute->getAttributeCode()] = [ + 'code' => $attribute->getAttributeCode(), + 'value' => '', + 'name' => '', + ]; + } + return $imageTypes; + } + + /** + * @return array + */ + public function getMediaAttributes() + { + return $this->variationMediaAttributes->getMediaAttributes(); + } } diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php b/app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php index 21b44ea83dc4f..064c2fc1b4af5 100644 --- a/app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php +++ b/app/code/Magento/ConfigurableProduct/Model/Product/VariationHandler.php @@ -32,6 +32,11 @@ class VariationHandler /** @var \Magento\CatalogInventory\Api\StockConfigurationInterface */ protected $stockConfiguration; + /** + * @var \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes + */ + protected $variationMediaAttributes; + /** * @param Type\Configurable $configurableProduct * @param \Magento\Eav\Model\Entity\Attribute\SetFactory $attributeSetFactory @@ -46,7 +51,8 @@ public function __construct( \Magento\Eav\Model\EntityFactory $entityFactory, \Magento\Catalog\Model\ProductFactory $productFactory, \Magento\CatalogInventory\Api\StockConfigurationInterface $stockConfiguration, - \Magento\Catalog\Model\Product\Attribute\Backend\Media $media + \Magento\Catalog\Model\Product\Attribute\Backend\Media $media, + \Magento\ConfigurableProduct\Model\Product\VariationMediaAttributes $variationMediaAttributes ) { $this->configurableProduct = $configurableProduct; $this->attributeSetFactory = $attributeSetFactory; @@ -54,6 +60,7 @@ public function __construct( $this->productFactory = $productFactory; $this->stockConfiguration = $stockConfiguration; $this->media = $media; + $this->variationMediaAttributes = $variationMediaAttributes; } /** @@ -209,7 +216,7 @@ public function duplicateImagesForVariations($productsData) $variationId = $image['variation_id']; $newFile = $this->media->duplicateImageFromTmp($file); $productsData[$variationId]['media_gallery']['images'][$imageId]['file'] = $newFile; - foreach (['small_image', 'thumbnail', 'image'] as $imageType) { + foreach ($this->variationMediaAttributes->getMediaAttributes() as $imageType => $attribute) { if (isset($productsData[$variationId][$imageType]) && $productsData[$variationId][$imageType] == $file ) { diff --git a/app/code/Magento/ConfigurableProduct/Model/Product/VariationMediaAttributes.php b/app/code/Magento/ConfigurableProduct/Model/Product/VariationMediaAttributes.php new file mode 100644 index 0000000000000..b40ac808aef8d --- /dev/null +++ b/app/code/Magento/ConfigurableProduct/Model/Product/VariationMediaAttributes.php @@ -0,0 +1,54 @@ +productFactory = $productFactory; + } + + /** + * Get media attributes for Configurable variation + * + * @return array + */ + public function getMediaAttributes() + { + if (null === $this->mediaAttributes) { + $this->mediaAttributes = $this->getProduct()->getMediaAttributes(); + } + return $this->mediaAttributes; + } + + /** + * Get product container for Simple product + * + * @return \Magento\Catalog\Model\Product + */ + private function getProduct() + { + return $this->productFactory->create()->setTypeId(\Magento\Catalog\Model\Product\Type::TYPE_SIMPLE); + } +} diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/bulk.phtml b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/bulk.phtml index df8785085dea3..3bee8679caa61 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/bulk.phtml +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/templates/catalog/product/edit/attribute/steps/bulk.phtml @@ -63,7 +63,13 @@
-