hello,
following this:
https://codeblog.experius.nl/magento-2-add-extra-billing-or-shipping-field-to-the-checkout/
I am trying to add a custom attribute to customer address. Inside:
/app/code/Hoop/Taxcode/Plugin/Magento/Quote/Model
I have a file named ShippingAddressManagement.php, with this code:
<?php
namespace Hoop\Taxcode\Plugin\Magento\Quote\Model;
class ShippingAddressManagement {
    protected $logger;
    public function __construct(
        \Psr\Log\LoggerInterface $logger
    ) {
        $this->logger = $logger;
    }
    public function beforeAssign(
        \Magento\Quote\Model\ShippingAddressManagement $subject,
        $cartId,
        \Magento\Quote\Api\Data\AddressInterface $address
    ) {
        $extAttributes = $address->getExtensionAttributes();
        if (!empty($extAttributes)) {
            try {
                $address->setTaxcode($address->getTaxcode());
            } catch (\Exception $e) {
                $this->logger->critical($e->getMessage());
            }
        }
    }
}but when I try to compile I get this:
[InvalidArgumentException]
  Plugin class Hoop_Taxcode\Plugin\Magento\Quote\Model\ShippingAddressManagement doesn't exist
what am I doing wrong?
Thanks
Solved! Go to Solution.
Just replace your plugin path with below,
Hoop_Taxcode with Hoop\Taxcode
type="Hoop_Taxcode\Plugin\Magento\Quote\Model\BillingAddressManagement" replace withtype="Hoop\Taxcode\Plugin\Magento\Quote\Model\BillingAddressManagement"
And shippingAddressmanagement with below way,
type="Hoop_Taxcode\Plugin\Magento\Quote\Model\BillingAddressManagement"
replace with
type="Hoop\Taxcode\Plugin\Magento\Quote\Model\ShippingAddressManagement"
Remove var/generation folder and clear cache.
Thanks.
Can you show your di.xml file code?
Hi,
this is my etc/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\Quote\Model\BillingAddressManagement">
        <plugin disabled="false" name="Hoop_Taxcode_Plugin_Magento_Quote_Model_BillingAddressManagement" sortOrder="10" type="Hoop_Taxcode\Plugin\Magento\Quote\Model\BillingAddressManagement"/>
    </type>
    <type name="Magento\Quote\Model\ShippingAddressManagement">
        <plugin disabled="false" name="Hoop_Taxcode_Plugin_Magento_Quote_Model_ShippingAddressManagement" sortOrder="10" type="Hoop_Taxcode\Plugin\Magento\Quote\Model\ShippingAddressManagement"/>
    </type>
</config>and this is my etc/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\Checkout\Block\Onepage">
        <arguments>
            <argument name="layoutProcessors" xsi:type="array">
                <item name="hoop_extra_checkout_address_fields_layoutprocessor" xsi:type="object">Hoop\Taxcode\Block\Checkout\LayoutProcessor</item>
            </argument>
        </arguments>
    </type>
</config>thanks!
Just replace your plugin path with below,
Hoop_Taxcode with Hoop\Taxcode
type="Hoop_Taxcode\Plugin\Magento\Quote\Model\BillingAddressManagement" replace withtype="Hoop\Taxcode\Plugin\Magento\Quote\Model\BillingAddressManagement"
And shippingAddressmanagement with below way,
type="Hoop_Taxcode\Plugin\Magento\Quote\Model\BillingAddressManagement"
replace with
type="Hoop\Taxcode\Plugin\Magento\Quote\Model\ShippingAddressManagement"
Remove var/generation folder and clear cache.
Thanks.
Hey Rakesh,
that worekd, thanks. But now when I try to order, I get this exception:
Message: Property "Taxcode" does not have corresponding setter in class "Magento\Quote\Api\Data\AddressExtensionInterface". in /var/www/coronelli/vendor/magento/framework/Webapi/ErrorProcessor.php:195
and in fact, inside var/generation/Magento/Quote/Api/Data/AddressExtension.php and var/generation/Magento/Quote/Api/Data/AddressExtensionInterface.php I expected to have getters and setters, instead I see for example:
<?php
namespace Magento\Quote\Api\Data;
/**
 * Extension class for @see \Magento\Quote\Api\Data\AddressInterface
 */
class AddressExtension extends \Magento\Framework\Api\AbstractSimpleObject implements \Magento\Quote\Api\Data\AddressExtensionInterface
{
}what am I missing?
thanks a lot
Hi @agiorgini , Ini extension_attributes.xml, it should be Magento\Quote\Api\Data\AddressInterface
could you share your complete implementation? please. im trying to follow that tutorial, but i have multiple errors ![]()
thanks in advance