1

I upgraded from the beta4 to the Magento 2.0.0 release. Now, I plugin I defined is no longer executed.

My app/code/Example/Product/etc/frontend/di.xml looks like this:

<?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\Checkout\Controller\Cart\Add">
          <plugin name="forceJson" type="Example\Product\Controller\Checkout\Plugin" sortOrder="1"/>
      </type>
      <type name="Magento\Checkout\Controller\Cart">
          <plugin name="forceJson" type="Example\Product\Controller\Checkout\Plugin" sortOrder="1"/>
      </type>
      <type name="Magento\Quote\Model\ShippingMethodManagementInterface">
          <plugin name="allowEmptyQuotes" type="Example\Product\Model\Quote\ShippingMethodManagement\Plugin" sortOrder="1"/>
      </type>
</config>

My app/code/Example/Product/Model/Quote/ShippingMethodManagement/Plugin.php

namespace Example\Product\Model\Quote\ShippingMethodManagement;

use Magento\Quote\Model\Cart\ShippingMethodConverter;
use Magento\Quote\Model\QuoteRepository;

class Plugin
{
      /**
       * Quote repository.
       *
       * @var QuoteRepository
       */
      protected $quoteRepository;

      /**
       * Shipping method converter
       *
       * @var \Magento\Quote\Model\Cart\ShippingMethodConverter
       */
      protected $converter;

      /**
       * @param QuoteRepository $quoteRepository Quote repository.
       */
      public function __construct(
          QuoteRepository $quoteRepository,
          ShippingMethodConverter $converter
      ) {
          $this->quoteRepository = $quoteRepository;
          $this->converter = $converter;
      }

      /**
       * Allow empty quote for calculating the shipping methods / costs
       *
       * Plugin for: @see \Magento\Quote\Model\ShippingMethodManagement::estimateByAddress
       *
       * @param $subject
       * @param $result
       */
      public function aroundEstimateByAddress(
          \Magento\Quote\Model\ShippingMethodManagement $subject,
          \Closure $proceed,
          $cartId,
          \Magento\Quote\Api\Data\EstimateAddressInterface $address
      ) {
            // [...]
            xdebug_break(); // never called

      }
}

When I debug into \Magento\Quote\Model\ShippingMethodManagement\Interceptor::estimateByAddress, this function is called, but there $pluginInfo is null, so my plugin is not executed.

What change did I miss between beta4 and 2.0.0 ? My module does have a registration.php, and other parts of the module are loaded. If I put a syntax error in my di.xml, the Magento instance crashes as expected.

1 Answer 1

1

It does work, when I move my di.xml from etc/frontend to etc/ in my module. Not sure why.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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