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

Php 如何以编程方式创建已登录客户的订单?,php,magento,Php,Magento,目前,我使php脚本生成订单未登录的客户,但我想使用此脚本为登录的客户动态登录的客户我的代码是 $quote = Mage::getModel('sales/quote') ->setStoreId(Mage::app()->getStore('default')->getId()); // for guest orders only: $quote->setCustomerEmail('customer@email.com'); //} // add produc

目前,我使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());
}
此脚本以编程方式创建订单,不记录在客户中

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

    $quote->setCustomerId()->setCustomerIsGuest(false)->setCustomerFirstname()->setCustomerLastname()->setCustomerGroupId();
这将为提供的客户信息创建订单。希望这会有所帮助