当前位置: 动力学知识库 > 问答 > 编程问答 >

rest - Convert created quote to the guest user for checkout

问题描述:

<?php

//session_name("frontend");

//session_start();

//$cartInfo = $_GET['items'];

require_once 'app/Mage.php';

Mage::init('default');

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

$quoteObj = Mage::getSingleton('checkout/cart')->getQuote()->load();

//print_r($quoteObj->load('126','customer_id')); die;

$cartArray = array(100=>1);

foreach ($cartArray as $key=> $value) {

$productId = $key;

$productQuantity = $value;

$productModel = Mage::getSingleton('catalog/product');

$productObj = $productModel->load($productId);

if (!$quoteObj) {

// echo 'if'; die;

$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 />';

}

I have this code which when I put on my root magento directory creates a quote and I can see that in the database.

Now how can I convert and assign the created quote to the guest user,

perhaps by using toOrder Method.Then I can let the user checkout as guestBut I am not sure how to do this for my API.

分享给朋友:
您可能感兴趣的文章:
随机阅读: