2013-03-01 58 views
0

Magento平台马上就要求客户注册一个账户,将其物品添加到购物车,然后检查出来。我将如何去除所有这些麻烦并实现一键订单功能,而无需添加到购物车?一键快速订单功能

为了演示,看看这个链接:http://royalglasses.pk/index.php/brands/ray-ban-pakistan/ray-ban-aviator-exclusive.html

在右边,你会看到一个“订单式”部分,在这里客户可以输入自己的信息,并检查了他们这样做的每一个人他们希望购买的物品。

我还要提到的是店里唯一的船舶在城市里面,有只有一个方法支付的,那就是,“货到付款”。因此,通常Magento交易(发货方式和付款信息)中的最后两个步骤对我的客户无效。

回答

0

我会继续遵循Magento逻辑,而不会破坏它的正常流程。来自我之前完成的脚本的代码片段描述了来宾客户的完整结账流程。你的应该不会有太大的不同。请不要复制和粘贴,查看代码并根据需要调整代码。

 
//Load the product from the posted form and cart and quote models. 
$product = Mage::getModel('catalog/product')->load((int) $_POST['product_id']); 
$cart = Mage::getSingleton('checkout/cart'); 
$quote = $cart->getQuote(); 

//Add the product to the cart and set the session to updated 
$params = array('product' => $product->getId(), 'qty' => (int) $_POST['qty']); 
$cart->addProduct($product, $params); 
$cart->save(); 
Mage::getSingleton('checkout/session')->setCartWasUpdated(true); 

//Load variables needed for the order process and transaction object to save the order. 
$transaction = Mage::getModel('core/resource_transaction'); 
$storeId = $customer->getStoreId(); 
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId); 

//Load the order model and set some default values 
$order = Mage::getModel('sales/order') 
       ->setIncrementId($reservedOrderId) 
       ->setStoreId($storeId) 
       ->setQuoteId($quote->getId()) 
       ->setGlobalCurrencyCode('USD') 
       ->setBaseCurrencyCode('USD') 
       ->setStoreCurrencyCode('USD') 
       ->setOrderCurrencyCode('USD'); 

//Assign customer as guest, $customer is array from $_POST['customer']  
$order->setCustomerEmail($customer['email']) 
       ->setCustomerFirstname($customer['firstname']) 
       ->setCustomerLastname($customer['lastname']) 
       ->setCustomerGroupId(0) 
       ->setCustomerIsGuest(1); 

//Prepare billing address and add it to the order 
$billingAddress = Mage::getModel('sales/order_address') 
       ->setStoreId($storeId) 
       ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING) 
       ->setCustomerId(0) 
       ->setCustomerAddressId(0) 
       ->setCustomerAddressId(0) 
       ->setFirstname($customer['firstname']) 
       ->setLastname($customer['lastname']) 
       ->setStreet($customer['address']) 
       ->setCity($customer['city']) 
       ->setCountryId($customer['country_id']) 
       ->setPostcode($customer['postcode']) 
       ->setTelephone($customer['phone']); 
$order->setBillingAddress($billingAddress); 

//Prepare shipping address and add it to the order, then set the shipping method 
$shippingAddress = Mage::getModel('sales/order_address') 
       ->setStoreId($storeId) 
       ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING) 
       ->setCustomerId(0) 
       ->setCustomerAddressId(0) 
       ->setCustomerAddressId(0) 
       ->setFirstname($customer['firstname']) 
       ->setLastname($customer['lastname']) 
       ->setStreet($customer['address']) 
       ->setCity($customer['city']) 
       ->setCountryId($customer['country_id']) 
       ->setPostcode($customer['postcode']) 
       ->setTelephone($customer['phone']); 

//Add the shipping address and the shipping method.    
$order->setShippingAddress($shippingAddress) 
       ->setShippingMethod('yourshipping_code') 
       ->setShippingDescription('Your shipping description'); 

//Add your payment method. 
$orderPayment = Mage::getModel('sales/order_payment') 
            ->setStoreId($storeId) 
            ->setCustomerPaymentId(0) 
            ->setMethod('cod'); //cod is Cash on Delivery 
$order->setPayment($orderPayment); 


//Loop through the items in the quote, create order item and add it to the order, you have only one product, so it will add only one order item. 
foreach ($quote->getItemsCollection() as $item) 
{ 
    $_prod = Mage::getModel('catalog/product')->load($item->getProduct()->getId()); 
    $rowTotal = $item->getCalculationPrice() * $item->getQty(); 
    $orderItem = Mage::getModel('sales/order_item') 
        ->setStoreId($storeId) 
        ->setQuoteItemId(0) 
        ->setQuoteParentItemId(NULL) 
        ->setProductId($_prod->getId()) 
        ->setProductType($_prod->getTypeId()) 
        ->setQtyBackordered(NULL) 
        ->setTotalQtyOrdered($item->getQty()) 
        ->setQtyOrdered($item->getQty()) 
        ->setName($_prod->getName()) 
        ->setSku($_prod->getSku()) 
        ->setPrice($item->getPrice()) 
        ->setBasePrice($item->getPrice()) 
        ->setOriginalPrice($item->getPrice()) 
        ->setRowTotal($rowTotal) 
        ->setBaseRowTotal($rowTotal); 
    $order->addItem($orderItem); 
} 

//Set the totals 
$subTotal = $quote->getGrandTotal(); 
$order->setSubtotal($subTotal) 
     ->setBaseSubtotal($subTotal) 
     ->setGrandTotal($subTotal) 
     ->setBaseGrandTotal($subTotal); 


//First, place the order, then save it.  
$transaction->addObject($order); 
$transaction->addCommitCallback(array($order, 'place')); 
$transaction->addCommitCallback(array($order, 'save')); 
$transaction->save(); 
$quote->save(); 

//Clear the session and the cart. 
Mage::getSingleton('checkout/session')->clear(); 
foreach($quote->getItemsCollection() as $_item) 
{ 
    Mage::getSingleton('checkout/cart')->removeItem($_item->getId())->save(); 
} 

//Redirect the user back to where you want.