如何以编程方式登录客户创建订单?

时间:2015-11-24 07:15:32

标签: php magento

目前我制作php脚本以生成未登录客户的订单但我想使用此脚本动态登录客户登录客户我的代码是

$quote = Mage::getModel('sales/quote')

->setStoreId(Mage::app()->getStore('default')->getId());


// for guest orders only:
$quote->setCustomerEmail('customer@email.com');
//}
// add product(s)
$product = Mage::getModel('catalog/product')->load(1307,1305);
$buyInfo = array(
'qty' => 1,
// custom option id => value id
// or
// configurable attribute id => value id
);
$quote->addProduct($product, new Varien_Object($buyInfo));
//$quote->addProduct($product2, new Varien_Object($buyInfo));
$addressData = array(
'firstname' => 'Test',
'lastname' => 'Test',
'street' => 'Sample Street 10',
'city' => 'Somewhere',
'postcode' => '123456',
'telephone' => '123456',
'country_id' => 'US',
'region_id' => 12, // id from directory_country_region table
);
$billingAddress = $quote->getBillingAddress()->addData($addressData);
$shippingAddress = $quote->getShippingAddress()->addData($addressData);
$shippingAddress->setCollectShippingRates(true)->collectShippingRates()
->setShippingMethod('flatrate_flatrate')
->setPaymentMethod('checkmo');
$quote->getPayment()->importData(array('method' => 'checkmo'));
$quote->collectTotals()->save();
echo "quote save";
$service = Mage::getModel('sales/service_quote', $quote);
$service->submitAll();
echo "order save";
$order = $service->getOrder();
printf("Created order %s\n", $order->getIncrementId());
}catch(Exception $e){

    print_r($e->getMessage());
}

此脚本是以编程方式为未登录的客户创建订单

1 个答案:

答案 0 :(得分:1)

Arvind的,

遵循相同的引用对象。在quote对象中使用以下方法为登录客户创建订单。

    $quote->setCustomerId()->setCustomerIsGuest(false)->setCustomerFirstname()->setCustomerLastname()->setCustomerGroupId();

这将创建所提供客户信息的订单。希望这会有所帮助。