We have created one module through which we can create upload images & from product detail page we can get the list of those images in a grid & whatever images we select those will be seen in front in product page.
This module works fine in Magento 2.0.x but not working in magento 2.1.x the problem is here :-
We have one observer which is being called when we save the product & in that we get the product id & the selected images ids....now the issue is we do not get images ids in 2.1.x
Event is : catalog_product_save_after
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Event/etc/events.xsd">
<event name="catalog_product_save_after">
<observer name="sticker" instance="Els\Sk\Observer\Adminhtml\Product" />
</event>
</config>
Here is our Observer Code :-
<?php
namespace Els\Sk\Observer\Adminhtml;
use Magento\Framework\Event\Observer as EventObserver;
use Magento\Framework\Event\ObserverInterface;
class Product implements ObserverInterface
{
protected $resourceConnection;
protected $eavAttributeFactory;
protected $request;
protected $_resources;
public function __construct(
\Magento\Framework\App\Request\Http $request,
\Magento\Framework\App\ResourceConnection $resourceConnection,
\Magento\Eav\Model\Entity\AttributeFactory $eavAttributeFactory
) {
$this->request = $request;
$this->resourceConnection = $resourceConnection;
$this->eavAttributeFactory = $eavAttributeFactory;
}
/**
* Saving product images data.
*
* @param EventObserver $observer
* @return $this
*/
public function execute(EventObserver $observer)
{
$product = $observer->getEvent()->getProduct();
$product_id = $product->getId();
/* We are not getting this in 2.1.x so this is the real issue */
$images_ids = $this->request->getPost("images_id");
$this->imageInsert($images_ids , $product_id);
}
?>
Can any one please help with this?
Thank you.