1

I got the code working for creating quote object and quote item object, and I'm able to create quote successfully which I could confirm it by checking the database, I also created cookie named front-end. All I need now is to assign the created quote to the guest user, so that I can let the user checkout as guest, but couldn't assign the cart to the guest user.

Request for items in the cart will be coming from 3rd party site via JSON request which I have decoded and looped through.

Here is the code

session_name("frontend");

session_start();

$cartInfo = $_GET['items'];

require_once '../app/Mage.php'; 

Mage::init('default');

$session = Mage::getSingleton('customer/session');

Mage::getSingleton('checkout/cart')->getQuote();

foreach ($cartArray as $key=> $value) {
        $productId = $key;
        $productQuantity = $value;
        $productModel = Mage::getSingleton('catalog/product');
        $productObj = $productModel->load($productId);
        if (!$quoteObj) {
            $quoteObj = new Mage_Sales_Model_Quote();
        }

        $store_id = Mage::app()->getStore()->getId();
        $storeObj = $quoteObj->getStore()->load($store_id);
        $quoteObj->setStore($storeObj);

        $quoteItem = Mage::getModel('sales/quote_item')->setProduct($productObj);
        $quoteItem->setQuote($quoteObj);
        $quoteItem->setQty($productQuantity);
        $quoteItem->setStoreId($store_id);

        $quoteObj->addItem($quoteItem);
        $quoteObj->setStoreId($store_id);
        $quoteObj->collectTotals();
        $quoteObj->setCustomerId(null);
        $quoteObj->save();
        $quoteId = $quoteObj->entity_id;
        echo $quoteObj->entity_id.'**<br />';
        echo $quoteItem->item_id.'---<br />';
}

2 Answers 2

1

Finally figured out the issue, hope it helps someone, here is the answer.

The above given code in the question section works perfectly, all you have to do is place the custom file in the root folder of your magento installation, if you create a folder and place this code, it wont work. It is must that the code file has to be in the root.

1
  • 2
    Your ""solution"" needs to be more technical. This is a bit useless without technical resources.
    – Machado
    Commented Oct 27, 2016 at 12:01
0

Since this is a guess checkout, the only way I can think of is to let the customer re-load the quote in their browser. So you would need to either email them a link with the quote id or let them enter the quote id on your site.

To Reload Quote in your controller

 $id = $this->getRequest()->getParam('quote_id');
 $store_id = $this->getRequest()->getParam('store_id');

 ....   
 $this->_getSession()->clear();
 $this->_getQuote()
      ->setQuoteId($id)
      ->setStoreId($store_id)
      ->setIsActive(true)
      ->load($id);
1
  • Is there any way I can attach the quote to the guest in the custom page itself that I created?
    – Bobby
    Commented Jul 29, 2014 at 6:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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