-
-
Notifications
You must be signed in to change notification settings - Fork 452
Media Gallery behavior when duplicating a product: Keep/Skip product images #5083
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| <?php | ||
|
|
||
| class Mage_Adminhtml_Model_System_Config_Source_Catalog_ImageDuplicate { | ||
|
|
||
|
|
||
| public function toOptionArray() | ||
| { | ||
| return [ | ||
| ['value' => -1, 'label' => Mage::helper('adminhtml')->__('Always ask')], | ||
| ['value' => 0, 'label' => Mage::helper('adminhtml')->__('Copy images to the new product')], | ||
| ['value' => 1, 'label' => Mage::helper('adminhtml')->__('Duplicate product without images')], | ||
| ]; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -20,6 +20,8 @@ class Mage_Catalog_Helper_Image extends Mage_Core_Helper_Abstract | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public const XML_NODE_PRODUCT_MAX_DIMENSION = 'catalog/product_image/max_dimension'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| public const XML_NODE_SKIP_IMAGE_ON_DUPLICATE_ACTION = 'catalog/product_image/images_on_duplicate_action'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| protected $_moduleName = 'Mage_Catalog'; | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
|
|
@@ -650,4 +652,12 @@ public function validateUploadFile($filePath) | |||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| return $mimeType !== null; | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||
| * @return int | ||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||
| public function skipProductImageOnDuplicate() | ||||||||||||||||||||||||
| { | ||||||||||||||||||||||||
| return Mage::getStoreConfigAsInt(self::XML_NODE_SKIP_IMAGE_ON_DUPLICATE_ACTION); | ||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
|
Comment on lines
+656
to
+662
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||
| } | ||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -56,6 +56,8 @@ | |||||||||||||||||||||
| * @method bool getIsChangedWebsites() | ||||||||||||||||||||||
| * @method bool getIsCustomOptionChanged() | ||||||||||||||||||||||
| * @method bool getIsDefault() | ||||||||||||||||||||||
| * @method bool getSkipImagesOnDuplicate() | ||||||||||||||||||||||
| * @method $this setSkipImagesOnDuplicate(bool $value) | ||||||||||||||||||||||
| * @method bool getIsDuplicate() | ||||||||||||||||||||||
| * @method bool getIsMassupdate() | ||||||||||||||||||||||
| * @method bool getIsRecurring() | ||||||||||||||||||||||
|
|
@@ -1365,6 +1367,12 @@ public function duplicate() | |||||||||||||||||||||
| ->setId(null) | ||||||||||||||||||||||
| ->setStoreId(Mage::app()->getStore()->getId()); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| if($newProduct->getSkipImagesOnDuplicate() == null && $this->_getImageHelper()->skipProductImageOnDuplicate() === -1){ | ||||||||||||||||||||||
| $newProduct->setSkipImagesOnDuplicate(false); | ||||||||||||||||||||||
| }else{ | ||||||||||||||||||||||
| $newProduct->setSkipImagesOnDuplicate((bool) $this->_getImageHelper()->skipProductImageOnDuplicate()); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
Comment on lines
+1370
to
+1374
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Mage::dispatchEvent( | ||||||||||||||||||||||
| 'catalog_model_product_duplicate', | ||||||||||||||||||||||
| ['current_product' => $this, 'new_product' => $newProduct], | ||||||||||||||||||||||
|
|
@@ -1437,7 +1445,9 @@ public function duplicate() | |||||||||||||||||||||
| $newProduct->save(); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| $this->getOptionInstance()->duplicate($this->getId(), $newProduct->getId()); | ||||||||||||||||||||||
| $this->getResource()->duplicate($this->getId(), $newProduct->getId()); | ||||||||||||||||||||||
| $this->getResource() | ||||||||||||||||||||||
| ->setSkipImagesOnDuplicate($newProduct->getSkipImagesOnDuplicate()) | ||||||||||||||||||||||
| ->duplicate($this->getId(), $newProduct->getId()); | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| // TODO - duplicate product on all stores of the websites it is associated with | ||||||||||||||||||||||
| /*if ($storeIds = $this->getWebsiteIds()) { | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -28,6 +28,13 @@ | |||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| protected $_productCategoryTable; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Used when duplicating product | ||||||||||||||||||||||||||
| * | ||||||||||||||||||||||||||
| * @var string | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| protected $_skipImagesOnDuplicate = false; | ||||||||||||||||||||||||||
|
Comment on lines
+31
to
+36
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * Initialize resource | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
|
|
@@ -565,9 +572,22 @@ | |||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||
| $adapter = $this->_getWriteAdapter(); | ||||||||||||||||||||||||||
| $eavTables = ['datetime', 'decimal', 'int', 'text', 'varchar']; | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| $mediaImageAttributeSkipIds = []; | ||||||||||||||||||||||||||
| $adapter = $this->_getWriteAdapter(); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if($this->getSkipImagesOnDuplicate()){ | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * @var int $attributeId | ||||||||||||||||||||||||||
| * @var Mage_Eav_Model_Entity_Attribute_Abstract $attribute | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| foreach($this->getAttributesById() as $attributeId => $attribute){ | ||||||||||||||||||||||||||
| if($attribute->getFrontendInput() == 'media_image'){ | ||||||||||||||||||||||||||
| $mediaImageAttributeSkipIds[$attribute->getBackendType()][] = $attributeId; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| // duplicate EAV store values | ||||||||||||||||||||||||||
| foreach ($eavTables as $suffix) { | ||||||||||||||||||||||||||
| $tableName = $this->getTable(['catalog/product', $suffix]); | ||||||||||||||||||||||||||
|
|
@@ -583,6 +603,10 @@ | |||||||||||||||||||||||||
| ->where('entity_id = ?', $oldId) | ||||||||||||||||||||||||||
| ->where('store_id > ?', 0); | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| if(isset($mediaImageAttributeSkipIds[$suffix])){ | ||||||||||||||||||||||||||
| $select->where('attribute_id NOT IN (?)', $mediaImageAttributeSkipIds[$suffix]); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| $adapter->query($adapter->insertFromSelect( | ||||||||||||||||||||||||||
| $select, | ||||||||||||||||||||||||||
| $tableName, | ||||||||||||||||||||||||||
|
|
@@ -719,4 +743,22 @@ | |||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| return $this->_getReadAdapter()->fetchCol($select); | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * @param bool $newProductSkipImages | ||||||||||||||||||||||||||
| * @return $this | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| public function setSkipImagesOnDuplicate(bool $newProductSkipImages){ | ||||||||||||||||||||||||||
| $this->_skipImagesOnDuplicate = $newProductSkipImages; | ||||||||||||||||||||||||||
|
Comment on lines
+747
to
+752
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
| return $this; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
| /** | ||||||||||||||||||||||||||
| * @return bool|string | ||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||
| public function getSkipImagesOnDuplicate(){ | ||||||||||||||||||||||||||
| return $this->_skipImagesOnDuplicate; | ||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
|
Comment on lines
+756
to
+761
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||
|
Comment on lines
+762
to
+763
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe add a new method
getDuplicateSkipUrl()?