我正在尝试通过插件保存我的自定义字段数据,但是它不起作用。
插件类
namespace Vendor\Module\Model\Checkout;
class PaymentInformationManagementPlugin {
protected $paymentMethodManagement;
public function __construct(
\Magento\Quote\Model\QuoteFactory $quote,
\Magento\Quote\Api\PaymentMethodManagementInterface $paymentMethodManagement
) {
$this->paymentMethodManagement = $paymentMethodManagement;
$this->quoteManagement = $quoteManagement;
}
public function beforeSavePaymentInformation(
\Magento\Checkout\Model\PaymentInformationManagement $subject,
$cartId,
\Magento\Quote\Api\Data\PaymentInterface $paymentInformation
) {
//$paymentInformation->getData('extension_attributes');
$extenstinAttributes = $paymentInformation->getExtensionAttributes();
$taxCode = $extenstinAttributes->getTaxCode();
$paymentInformation->setExtensionAttributes($taxCode);
$this->paymentMethodManagement->set($cartId, $paymentInformation);
return true;
// var_dump($taxCode);exit;
// $quote=$this->quote->create();
// $quote->getPayment()->setData('tax_code',$taxCode);
// return $paymentInformation;
}
}
extenstion_attribute.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
<extension_attributes for="Magento\Quote\Api\Data\PaymentInterface">
<attribute code="tax_code" type="string"/>
</extension_attributes>
</config>
di.xml
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
<type name="Magento\Checkout\Model\PaymentInformationManagement">
<plugin name="save-in-quote-payment" type="Vendor\Module\Model\Checkout\PaymentInformationManagementPlugin" sortOrder="12349"/>
</type>
</config>
谁能帮我这个忙。
通过配置显示更多详细信息
—
Sohel Rana
我正在获取值$ taxCode = $ extenstinAttributes-> getTaxCode(); 在此变量中,但无法设置数据。
—
rajat kara
请检查有问题的更新代码
—
rajat kara
我在插件中获取表单数据,但无法保存数据。
—
rajat kara
你这样做了吗?
—
Suresh Chikani