Php 自动单页签出-报价问题
我正在创建自动结帐功能,它将一次创建几个订单: 怎么了 假设这个脚本为不同的用户创建了4个不同的订单,使用不同的prodcuts,但问题在于,在第一个订单之后创建的每个订单都得到了第一个订单的小计和总计。我怎样才能重置它 Mage::app'default'Php 自动单页签出-报价问题,php,magento,zend-framework,Php,Magento,Zend Framework,我正在创建自动结帐功能,它将一次创建几个订单: 怎么了 假设这个脚本为不同的用户创建了4个不同的订单,使用不同的prodcuts,但问题在于,在第一个订单之后创建的每个订单都得到了第一个订单的小计和总计。我怎样才能重置它 Mage::app'default' /** * Get the resource model */ $resource = Mage::getSingleton('core/resource'); /** * Retrieve the read connection
/**
* Get the resource model
*/
$resource = Mage::getSingleton('core/resource');
/**
* Retrieve the read connection
*/
$readConnection = $resource->getConnection('core_read');
$query = 'SELECT * FROM m4gsrepeated_orders WHERE execution <= CURDATE()';
$all_orders = $readConnection->fetchAll($query);
function addCartItems($products_array) {
$cart = Mage::getModel('checkout/cart');
foreach($products_array as $productw) {
$sku = $productw[0];
/** @var $productCollection Mage_Catalog_Model_Resource_Product_Collection */
$productCollection = Mage::getModel( 'catalog/product' )
->getResourceCollection()
->addFieldToFilter( 'sku', $sku );
/** @var $product Mage_Catalog_Model_Product */
$product = $productCollection->getFirstItem();
// you should have the product now, maybe it isn't even necessary to get the ID
$product = $product->load($product->getId());
$cart->addProduct($product, $productw[1]);
}
$cart->save();
}
foreach ($all_orders as $order) {
//Set basic data
Mage::getSingleton('checkout/session')->getQuote()->setReservedOrderId(null);
$customer = Mage::getModel('customer/customer')
->setWebsiteId(Mage::app()->getStore()->getWebsiteId())
->load($order['user_id']);
// Set as Logged In and Clear Session
Mage::getSingleton('customer/session')->setCustomerAsLoggedIn($customer)->renewSession();
//Set up cart
$cart = Mage::getModel('checkout/cart')->getQuote();
//get current cart items;s
$i=1;
foreach ($cart->getAllItems() as $item) {
$products_current[$i][0] = $item->getProduct()->getSku();
$products_current[$i][1] = intval($item->getQty());
$i++;
}
$i=1;
$cart = Mage::getModel('checkout/cart');
foreach( Mage::getSingleton('checkout/session')->getQuote()->getItemsCollection() as $item ){
$cart->removeItem( $item->getId() );
}
$products_delayed = json_decode($order['items']);
addCartItems($products_delayed);
$cart->save();
//LUUUTA CREATE ORDER
# Get customer default shipping information
$customerAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultShipping();
if ($customerAddressId){
$address = Mage::getModel('customer/address')->load($customerAddressId);
$shippingAddress = $address->getData();
}
# Get customer default billing information
$customerAddressId = Mage::getSingleton('customer/session')->getCustomer()->getDefaultBilling();
if ($customerAddressId){
$address = Mage::getModel('customer/address')->load($customerAddressId);
$billingAddress = $address->getData();
}
$quote = Mage::getSingleton('checkout/session')->getQuote();
/*
* One page checkout consists of following steps
* (1) Customer login method aka Checkout method
* (2) Billing information (address)
* (3) Shipping information (address)
* (4) Shipping method
* (5) Payment information
* (6) Order review, in short: DO THE ORDER
*/
$storeId = Mage::app()->getStore()->getId();
$checkout = Mage::getSingleton('checkout/type_onepage');
$checkout->initCheckout();
$checkout->saveShippingMethod('excellence_excellence');
$quote->getShippingAddress()->setShippingMethod('excellence_excellence');
$quote->getShippingAddress()->unsGrandTotal(); //clear the values so they won't take part in calculating the totals
$quote->getShippingAddress()->unsBaseGrandTotal();
$quote->getShippingAddress()->setCollectShippingRates(true)->save();
$quote->getShippingAddress()->collectTotals(); //collect totals and ensure the initialization of the shipping methods
$quote->collectTotals();
//STEP(1)
$checkout->saveCheckoutMethod('register');
//STEP(2)
$checkout->saveBilling($billingAddress, false);
//STEP(3)
$checkout->saveShipping($shippingAddress, false);
//STEP(4)
$checkout->saveShippingMethod('excellence_excellence');
//STEP(5)
$checkout->savePayment(array('method'=>'pay'));
Mage::getSingleton('checkout/type_onepage')->getQuote()->getShippingAddress()->setShippingMethod('excellence_excellence');
//STEP(6)
/*
* $checkout->saveOrder() returns array holding empty object
* of type Mage_Checkout_Model_Type_Onepage
*/
try {
$checkout->saveOrder();
}
catch (Exception $ex) {
echo $ex->getMessage();
}
//addCartItems($products_delayed);
$cart->truncate();
$cart->save();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);
Mage::getSingleton('customer/session')->logout();
$customerAddressId = '';
}
问题已修复:
这取决于结帐/会话和必须清除的客户/会话
Mage::getSingleton('checkout/session')->clear();
Mage::getSingleton('customer/session')->clear();
这可能有助于使用类似方法解决批量排序问题
谢谢,
亚当