Skip to content

Commit

Permalink
Merge pull request #48 from lizardmedia/types-compatibility-fix
Browse files Browse the repository at this point in the history
Product types compatiblity fix
  • Loading branch information
Bartosz Kubicki authored Feb 15, 2021
2 parents 6760802 + c79655c commit 29b2267
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 5 deletions.
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,4 +51,7 @@
* fix for stale downloaded files in magento root

### 1.3.8 ###
* fix for not saving attachment
* fix for not saving attachment

### 1.3.9 ###
* compatibility with bundle and grouped product for Magento 2.3 and 2.4
59 changes: 59 additions & 0 deletions Observer/Adminhtml/TypeConvertingPrevention.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php

declare(strict_types=1);

/**
* File: TypeConvertingPrevention.php
*
* @author Bartosz Kubicki [email protected]>
* @copyright Copyright (C) 2021 Lizard Media (http://lizardmedia.pl)
*/

namespace LizardMedia\ProductAttachment\Observer\Adminhtml;

use Magento\Framework\App\RequestInterface;
use Magento\Framework\Event\Observer;
use Magento\Framework\Event\ObserverInterface;

/**
* Class TypeConvertingPrevention
* @package LizardMedia\ProductAttachment\Observer\Adminhtml
*/
class TypeConvertingPrevention implements ObserverInterface
{
/**
* @var RequestInterface
*/
private $request;

/**
* @param RequestInterface $request
*/
public function __construct(
RequestInterface $request
) {
$this->request = $request;
}

/**
* @param Observer $observer
* @return void
*/
public function execute(Observer $observer): void
{
$product = $observer->getEvent()->getProduct();
$type = $this->request->getParam('type');

if (!empty($type) && in_array($type, $this->getProductType(), true)) {
$product->setTypeId($type);
}
}

/**
* @return string[]
*/
private function getProductType(): array
{
return ['bundle', 'grouped'];
}
}
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"magento/module-ui": "*"
},
"type": "magento2-module",
"version": "1.3.8",
"version": "1.3.9",
"license": [
"MIT"
],
Expand Down
2 changes: 1 addition & 1 deletion etc/adminhtml/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,4 @@
</type>
<!-- End of proxy section -->

</config>
</config>
13 changes: 13 additions & 0 deletions etc/adminhtml/events.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0"?>
<!--
/**
* @author Bartosz Kubicki <[email protected]>
* @copyright Copyright (C) 2021 Lizard Media (http://lizardmedia.pl)
*/
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="catalog_product_save_before">
<observer name="LizardMedia_ProductAttachment::typeConvertingPrevention" instance="LizardMedia\ProductAttachment\Observer\Adminhtml\TypeConvertingPrevention"/>
</event>
</config>
2 changes: 1 addition & 1 deletion etc/di.xml
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,4 @@
</type>
<!-- End of metadataPool section -->

</config>
</config>
2 changes: 1 addition & 1 deletion etc/module.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
-->
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="urn:magento:framework:Module/etc/module.xsd">
<module name="LizardMedia_ProductAttachment" setup_version="1.3.8">
<module name="LizardMedia_ProductAttachment" setup_version="1.3.9">
<sequence>
<module name="Magento_Downloadable"/>
<module name="Magento_Catalog"/>
Expand Down

0 comments on commit 29b2267

Please sign in to comment.