0
magento 2のカスタムモジュールプラグインでカート製品を入手するにはどうすればよいですか?このように私はMagento 2のプラグイン機能でカートの詳細を取得する方法はありますか
を取得しています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 /app/code/Sem/Shipment/Plugin/Checkout/Model/ShippingInformationManagement.php
もカートの製品を取得する必要があります
$ items = $ this - > _ cart-> getAllVisibleItems();空の値としてこの商品はカートに入れられます