-
Notifications
You must be signed in to change notification settings - Fork 37
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #48 from lizardmedia/types-compatibility-fix
Product types compatiblity fix
- Loading branch information
Showing
7 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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']; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -48,4 +48,4 @@ | |
</type> | ||
<!-- End of proxy section --> | ||
|
||
</config> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,4 +100,4 @@ | |
</type> | ||
<!-- End of metadataPool section --> | ||
|
||
</config> | ||
</config> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters