Je travaille dans magento 2.2.2 et lorsque j'enregistre le produit, il affichera cette erreur.
Erreur fatale: taille de mémoire autorisée de 792723456 octets épuisée (tentative d'allocation de 184320 octets) dans /var/www/html/Demo/vendor/magento/framework/Profiler.php sur la ligne 153
Php version : 7.0
Magento : 2.2.2
J'ai aussi des changements s'appliquent dans memory_limit = 16G
au php.ini
fichier et redémarrez apache serveur. encore, ce problème n'est pas résolu.
<?php
namespace Abc\Xyz\Observer;
use Magento\Framework\Event\ObserverInterface;
use \Magento\Store\Model\StoreManagerInterface;
class ProductSaveAfter implements ObserverInterface
{
protected $_objectManager;
protected $messageManager;
protected $_productmFactory;
protected $_productdFactory;
protected $_productsFactory;
protected $_eavConfig;
protected $sStore;
protected $scopeConfig;
protected $_helper;
protected $storeManager;
public function __construct(
\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
\Magento\Framework\ObjectManagerInterface $objectManager,
\Magento\Framework\App\RequestInterface $request,
\Magento\Eav\Model\Config $eavConfig,
\Abc\Xyz\Helper\Data $helper,
StoreManagerInterface $storeManager,
\Abc\Xyz\Model\productmFactory $productmFactory,
\Abc\Xyz\Model\ProductdFactory $ProductdFactory,
\Abc\Xyz\Model\productsFactory $productsFactory,
\Abc\Xyz\Model\sStoreFactory $sStoreFactory,
\Magento\Framework\Message\ManagerInterface $messageManager
) {
$this->_objectManager = $objectManager;
$this->_request = $request;
$this->_helper = $helper;
$this->scopeConfig = $scopeConfig;
$this->_eavConfig = $eavConfig;
$this->_productmFactory = $productmFactory;
$this->_productdFactory = $ProductdFactory;
$this->_productsFactory = $productsFactory;
$this->sStore = $sStoreFactory;
$this->storeManager = $storeManager;
$this->messageManager = $messageManager;
}
public function execute(\Magento\Framework\Event\Observer $observer)
{
$product = $observer->getEvent()->getProduct();
$id = $product->getId();
$data = $this->_request->getParams();
$currentWebsite = $this->storeManager->getStore()->getWebsiteId();
try
{
if ($id) {
$YG14 = $this->_request->getParam('YG14');
$YG14_size = $this->_request->getParam('YG14_size');
$mI = $this->_productmFactory->create()->getCollection();
$mI->addFieldToFilter('product_id', $id);
/** Delete all records*/
if ($YG14 != "") {
if (!empty($mI)) {
foreach ($mI as $mtl) {
$mI = $this->_productmFactory->create()->load($mtl->getId());
$mI->delete();
}
}
}
if ($YG14 != "") {
$mISave = $this->_productmFactory->create();
$mISave->setProductId($id);
$mISave->setMtlWeight($YG14);
$mISave->setMtlType('YG14');
$mISave->setSizeIncrementWeightDiff($YG14_size);
$mISave->save();
}
$dD = $this->_request->getParam('d');
if ($dD) {
$dInfoDelete = $this->_productdFactory->create()->getCollection()->addFieldToFilter('product_id', $id);
foreach ($dInfoDelete as $key => $dia) {
$dInfo = $this->_productdFactory->create()->load($dia->getId());
$dInfo->delete();
}
foreach ($dD as $d) {
$dS = $this->_productdFactory->create();
$dS->setProductId($id);
if (array_key_exists('d_s', $d)) {
$dS->setDS($d['d_s']);
}
if (array_key_exists('d_w', $d)) {
$dS->setDW($d['d_w']);
}
if (array_key_exists('d_q', $d)) {
$dS->setDQ($d['d_q']);
}
if (array_key_exists('d_s_t', $d)) {
$dS->setDST($d['d_s_t']);
}
$dS->save();
}
} else {
$deld = $this->_request->getParam('deld');
if ($deld != "") {
$delD = explode(",", $deld);
foreach ($delD as $delDIds) {
$dD = $this->_productdFactory->create()->load($delDIds);
$dD->delete();
}
}
}
$sD = $this->_request->getParam('st');
if ($sD) {
foreach ($sD as $sts) {
$ssSave = $this->_productsFactory->create();
if (isset($sts['st_ids'])) {
$ssSave->setId($sts['st_ids']);
}
$ssSave->setProductId($id);
if (array_key_exists('st_c', $sts)) {
$ssSave->setStC($sts['st_c']);
}
if (array_key_exists('st_sett', $sts)) {
$ssSave->setStSett($sts['st_sett']);
}
if (array_key_exists('st_s', $sts)) {
$ssSave->setStS($sts['st_s']);
}
if (array_key_exists('st_w', $sts)) {
$ssSave->setStW($sts['st_w']);
}
if (array_key_exists('st_q', $sts)) {
$ssSave->setStQ($sts['st_q']);
}
$ssSave->save();
$sStore = $this->sStore->create();
$sStoreExists = $sStore->getCollection()->addFieldToFilter('st_id', $ssSave->getId())->addFieldToFilter('website_id', $currentWebsite);
if (!empty($sStoreExists->getData())) {
foreach ($sStoreExists as $value) {
$sStore->load($value->getId());
$sStore->setId($value->getId());
$sStore->setProductId($id);
$sStore->setPrice($sts['price']);
$sStore->save();
}
} else {
$sStore->setWebsiteId($currentWebsite);
$sStore->setProductId($id);
$sStore->setStId($ssSave->getId());
if (array_key_exists('price', $sts)) {
$sStore->setPrice($sts['price']);
}
$sStore->save();
}
}
$delSt = $this->_request->getParam('delSt');
if ($delSt != "") {
$delS = explode(",", $delSt);
foreach ($delS as $delSIds) {
$dDelete = $this->_productsFactory->create()->load($delSIds);
$dDelete->delete();
}
}
} else {
$delSt = $this->_request->getParam('delSt');
if ($delSt != "") {
$delS = explode(",", $delSt);
foreach ($delS as $delSIds) {
$dDelete = $this->_productsFactory->create()->load($delSIds);
$dDelete->delete();
}
}
}
$prices = $this->_helper->defaultPriceCalculate($id, $product, $currentWebsite);
$product->setWebsiteId($currentWebsite)->setPrice($prices['finalPrice']);
if ($prices['discountedPrice'] != 0) {
$product->setSpecialPrice($prices['discountedPrice']);
}
$product->save();
}
} catch (\Magento\Framework\Exception\LocalizedException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\RuntimeException $e) {
$this->messageManager->addError($e->getMessage());
} catch (\Exception $e) {
$this->messageManager->addException($e, __('Something went wrong while saving the post.'));
}
}
}
Comment le résoudre ?
Aidez-moi, s'il vous plaît.