Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $quote = $this->quoteRepository->getActive($cartId);
- // Extension Attributes
- $quoteExtension = $quote->getExtensionAttributes();
- $quoteExtension->setFromApp(true);
- $this->quoteRepository->save($quote);
- <?xml version="1.0"?>
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:Api/etc/extension_attributes.xsd">
- <extension_attributes for="MagentoQuoteApiDataCartInterface">
- <attribute code="from_app" type="string"/>
- </extension_attributes>
- <?xml version="1.0" encoding="UTF-8"?>
- <config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
- <type name="MagentoQuoteApiCartRepositoryInterface">
- <plugin name="vendor_namespace_plugin_cart_repository" type="VendorNamespacePluginCartRepositoryPlugin"/>
- </type>
- $quote->setFromApp(true);
- $this->quoteRepository->save($quote);
- $quote = $this->quoteRepository->getActive($cartId);
- // Extension Attributes
- $quoteExtension = $quote->getExtensionAttributes();
- $quoteExtension->setFromApp(true);
- $quote->setExtensionAttributes(quoteExtension);
- $this->quoteRepository->save($quote);
- <?php
- namespace VendorNamespacePlugin;
- use MagentoQuoteApiCartRepositoryInterface;
- use MagentoQuoteApiDataCartExtension;
- use MagentoQuoteApiDataCartExtensionFactory;
- use MagentoQuoteApiDataCartInterface;
- use MagentoQuoteApiDataCartSearchResultsInterface;
- /**
- * Class CartRepositoryPlugin
- */
- class CartRepositoryPlugin
- {
- /**
- * @var CartExtensionFactory
- */
- private $extensionFactory;
- /**
- * CartRepositoryPlugin constructor.
- *
- * @param CartExtensionFactory $orderExtensionFactory
- */
- public function __construct(
- CartExtensionFactory $orderExtensionFactory
- ) {
- $this->extensionFactory = $orderExtensionFactory;
- }
- /**
- * @param CartRepositoryInterface $subject
- * @param CartInterface $resultEntity
- * @return CartInterface
- * @SuppressWarnings(PHPMD.UnusedFormalParameter)
- */
- public function afterGet(
- CartRepositoryInterface $subject,
- CartInterface $resultEntity
- ) {
- /** @var CartExtension $extensionAttributes */
- $extensionAttributes = $resultEntity->getExtensionAttributes() ?: $this->extensionFactory->create();
- $extensionAttributes->setFromApp($resultEntity->getData('from_app'));
- $resultEntity->setExtensionAttributes($extensionAttributes);
- return $resultEntity;
- }
- /**
- * @param CartRepositoryInterface $subject
- * @param CartSearchResultsInterface $resultCart
- * @return CartSearchResultsInterface
- */
- public function afterGetList(
- CartRepositoryInterface $subject,
- CartSearchResultsInterface $resultCart
- ) {
- /** @var CartInterface $order */
- foreach ($resultCart->getItems() as $order) {
- $this->afterGet($subject, $order);
- }
- return $resultCart;
- }
- /**
- * @param CartRepositoryInterface $subject
- * @param CartInterface $result
- * @return array
- */
- public function beforeSave(
- CartRepositoryInterface $subject,
- CartInterface $quote
- ) {
- $extensionAttributes = $quote->getExtensionAttributes() ?: $this->extensionFactory->create();
- if ($extensionAttributes !== null && $extensionAttributes->getFromApp() !== null) {
- $quote->setFromApp($extensionAttributes->getFromApp());
- }
- return [$quote];
- }
- }
- /**
- * @param CartRepositoryInterface $subject
- * @param CartInterface $result
- * @return CartInterface
- */
- public function afterSave(
- CartRepositoryInterface $subject,
- CartInterface $result
- ) {
- $extensionAttributes = $result->getExtensionAttributes() ?: $this->storeExtensionFactory->create();
- if ($extensionAttributes !== null && $extensionAttributes->getFromApp() !== null) {
- /** @var CustomEntity $customEntity */
- $customEntity = $this->customEntityFactory->create();
- $customEntity->setQuoteId($result->getId());
- $customEntity->setFromApp($result->getFromApp());
- $this->customEntityRepository->save($customEntity);
- }
- return $result;
- }
Add Comment
Please, Sign In to add comment