0
  • I have added product to customer cart programmatically with custom prices as quatation.
  • Now customer should not add,remove or update cart items as it is fixed quatation.

How can i achieve this?

5
  • I guess you need to create a cart attribute and make before plugin for needed controller and check attribute value as needed. Mar 23 '19 at 9:15
  • i have idea about this i create quote attribute and check while updating cart item in observer Mar 23 '19 at 9:26
  • not sure what is better idea to get this Mar 23 '19 at 9:29
  • You can remove update qty box and delete button for that customer. For add product restriction, you can add this on cart controller. You will get customer id from session. May be this will help you.
    – user55548
    Mar 23 '19 at 12:05
  • I have solved it by using plugin method,Thanks all for suggestions Mar 25 '19 at 6:54
1
  • Add attribute to Quote if it is Quatation quote $quote->setClientQuote(1);

Create plugin method before product operation on cart and block all

<type name="Magento\Checkout\Model\Cart">
        <plugin name="interceptUpdateProductToCart" type="Ketan\Clientquote\Plugin\Clientquotecheck"/>
    </type>

Create Plugin file

<?php
namespace Ketan\Clientquote\Plugin;
use \Magento\Framework\Message\ManagerInterface ;

class Clientquotecheck
{

    /**
     * @var ManagerInterface
     */
    protected $_messageManager;

    /**
     * @var \Magento\Quote\Model\Quote
     */
    protected $quote;

    /**
     * Plugin constructor.
     *
     * @param \Magento\Checkout\Model\Session $checkoutSession
     */
    public function __construct(
        \Magento\Checkout\Model\Session $checkoutSession,
        ManagerInterface $messageManager
    ) {
        $this->quote = $checkoutSession->getQuote();
        $this->_messageManager = $messageManager;
    }

    /**
     * @param \Magento\Checkout\Model\Cart $subject
     * @param $data
     * @return array
     */

    public function beforeAddProduct(
        \Magento\Checkout\Model\Cart $subject,
        $productInfo,
        $requestInfo = null
    ) {
        $this->allowedMethod($subject);

        return [$productInfo, $requestInfo];
    }

    /**
     * Check if allowed function AddProductsByIds
     *
     * @param \Magento\Checkout\Model\Cart $subject
     * @param array $productIds
     * @return array
     * @throws \Exception
     */
    public function beforeAddProductsByIds(\Magento\Checkout\Model\Cart $subject, $productIds)
    {
        $this->allowedMethod($subject);

        return [$productIds];
    }

    /**
     * Check if allowed function UpdateItems
     *
     * @param \Magento\Checkout\Model\Cart $subject
     * @param array $data
     * @return array
     * @throws \Exception
     */
    public function beforeUpdateItems(\Magento\Checkout\Model\Cart $subject, $data)
    {
        $this->allowedMethod($subject);

        return [$data];
    }

    /**
     * Check if allowed function UpdateItem
     *
     * @param \Magento\Checkout\Model\Cart $subject
     * @param int|array|\Magento\Framework\DataObject $requestInfo
     * @param null|array|\Magento\Framework\DataObject $updatingParams
     * @return array
     * @throws \Exception
     */
    public function beforeUpdateItem(
        \Magento\Checkout\Model\Cart $subject,
        $requestInfo = null,
        $updatingParams = null
    ) {
        $this->allowedMethod($subject);

        return [$requestInfo, $updatingParams];
    }

    /**
     * Check if allowed function
     *
     * @param \Magento\Checkout\Model\Cart $subject
     * @param int $itemId
     * @return int
     * @throws \Exception
     */
    public function beforeRemoveItem(\Magento\Checkout\Model\Cart $subject, $itemId)
    {
        $this->allowedMethod($subject);

        return [$itemId];
    }

    /**
     * Blocks method if active confirm mode is set true to session
     *
     * @throws \Exception
     */
    public function allowedMethod($subject)
    {
        $quote = $subject->getQuote();

        if ($quote->getClientQuote()) {
            throw new \Exception('Action is blocked in quote confirmation mode.');
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.