Using the Magento REST API I am able to create and populate a cart on my external site, but I want customers to checkout on the actual Magento site. Right now I'm looking at creating a plugin for Checkout\Controller\Cart\Index. I want it to grab the cart_id from the request parameters and load that cart up to the session. Trouble is, I'm not really sure exactly where to start, and the documentation is lacking.

So far I have the plugin class written as:

class IndexPlugin
    public function beforeExecute() {
        $params = $this->getRequest()->getParams();
        if (isset($params['masked_id'])) {
            $quoteIdMask = $this->checkoutSession->quoteIdMaskFactory->create()->load($params['masked_id'], 'masked_id');

With the di.xml looking like:

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <type name="Magento\Checkout\Controller\Cart\Index">
        <plugin name="restore-cart-by-mask"
            type="{Vendor}\{Module}\Plugin\Checkout\Controller\Cart\Index" sortOrder="10"/>

I know this is a less than secure approach, so any guidance would be extremely appreciated.

  • Did you end up using that approach, or find a better solution? – Erfan Jul 19 '17 at 6:40

Your Answer

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

Browse other questions tagged or ask your own question.