0
如何在購買magento 2的自定義模塊插件的購物車產品之前保存運輸信息聽說我已將客戶地址的工作狀態這樣我需要讓車產品也有沒有任何方法可以在Magento 2的插件功能中獲取購物車的詳細信息
/app/code/Sem/Shipment/Plugin/Checkout/Model/ShippingInformationManagement.php
class ShippingInformationManagement
{
protected $_messageManager;
protected $jsonResultFactory;
protected $_cart;
public function __construct(
\Magento\Framework\App\Action\Context $context,
\Magento\Framework\Controller\Result\JsonFactory $jsonResultFactory,
\Magento\Framework\Message\ManagerInterface $messageManager,
\Magento\Framework\Controller\Result\JsonFactory $resultJsonFactory,
\Magento\Checkout\Model\Cart $cartModel
) {
$this->_messageManager = $messageManager;
$this->jsonResultFactory = $jsonResultFactory;
$this->_cart = $cartModel;
}
public function beforeSaveAddressInformation(
\Magento\Checkout\Model\ShippingInformationManagement $subject,
$cartId,
\Magento\Checkout\Api\Data\ShippingInformationInterface $addressInformation
)
{
$items = $this->_cart->getAllVisibleItems();
$result = [];
if (count($items) > 0){
foreach ($items as $item)
$resulta = $item->getName();
}
$address = $addressInformation->getShippingAddress();
$postcode = $address->getData('postcode');
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$result = $this->jsonResultFactory->create();
throw new StateException(__($resulta));
}
}
Heare我得到
$ items = $ this - > _ cart-> getAllVisibleItems();作爲空值,但產品在購物車中