0

I have a plugin running afterGetPrice(). This is working correctly in the frontend but does not work in the admin area. I have placed my di.xml in the following locations:

<moduleDir>/etc/frontend/di.xml
<moduleDir>/etc/adminhtml/di.xml

The content of these di.xml files is:

adminhtml/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin name="sulman-product-model-admin" type="Sulman\Test\Plugin\ProductPlugin" sortOrder="1" />
    </type>
</config>

frontend/di.xml

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Catalog\Model\Product">
        <plugin name="sulman-product-model-frontend" type="Sulman\Test\Plugin\ProductPlugin" sortOrder="1" />
    </type>
</config>   

My Plugin code is:

<?php
namespace Sulman\Test\Plugin;

class ProductPlugin
{
    protected $objectManager;

    public function __construct(\Magento\Framework\ObjectManagerInterface $objectManager)
    {
        $this->objectManager = $objectManager;
    }

    public function afterGetPrice(\Magento\Catalog\Model\Product $subject, $result)
    {
        return 123.45;
    }
}
?>

It all looks OK but it's not changing the price in the admin.

Any ideas?

(all cache etc cleaned, content deployed, etc etc)

0

Not all requests are in the frontend and adminhtml area. Try using a single file di.xml

<moduleDir>/etc/di.xml
1
  • Thank you. Adding the global di.xml didn't have any effect though.
    – sulman
    Jan 17 '18 at 13:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.