0

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

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

在右侧,您将看到一个“订单”部分,客户可以在其中输入他们的信息并结账,然后他们会为他们希望购买的每件商品执行此操作。

我还要提一下,这家商店只在城内发货,付款方式只有一种,即“货到付款”。因此,通常 Magento 交易中的最后两个步骤(运输方式和付款信息)对我的客户来说毫无用处。

4

1 回答 1

0

我会在不破坏其正常流程的情况下遵循 Magento 逻辑。我之前编写的脚本中的代码片段描述了来宾客户的完整结帐流程。你的应该没有太大的不同。请不要复制和粘贴,查看代码并根据您的需要进行调整。

//从发布的表单和购物车和报价模型中加载产品。
$product = Mage::getModel('catalog/product')->load((int) $_POST['product_id']);
$cart = Mage::getSingleton('checkout/cart');
$quote = $cart->getQuote();

//将产品添加到购物车并将会话设置为更新
$params = array('product' => $product->getId(), 'qty' => (int) $_POST['qty']);
$cart->addProduct($product, $params);
$cart->保存();
Mage::getSingleton('checkout/session')->setCartWasUpdated(true);

//加载订单流程和交易对象需要的变量来保存订单。
$transaction = Mage::getModel('core/resource_transaction');
$storeId = $customer->getStoreId();
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId);

//加载订单模型并设置一些默认值
$order = Mage::getModel('销售/订单')
                ->setIncrementId($reservedOrderId)
                ->setStoreId($storeId)
                ->setQuoteId($quote->getId())
                ->setGlobalCurrencyCode('USD')
                ->setBaseCurrencyCode('USD')
                ->setStoreCurrencyCode('USD')
                ->setOrderCurrencyCode('USD');

//将客户指定为客人,$customer 是来自 $_POST['customer'] 的数组      
$order->setCustomerEmail($customer['email'])
                ->setCustomerFirstname($customer['firstname'])
                ->setCustomerLastname($customer['lastname'])
                ->setCustomerGroupId(0)
                ->setCustomerIsGuest(1);

//准备账单地址并将其添加到订单中
$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);

//准备送货地址并添加到订单中,然后设置送货方式
$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']);

//添加送货地址和送货方式。             
$order->setShippingAddress($shippingAddress)
                ->setShippingMethod('yourshipping_code')
                ->setShippingDescription('您的运输描述');

//添加您的付款方式。
$orderPayment = Mage::getModel('sales/order_payment')
                                    ->setStoreId($storeId)
                                    ->setCustomerPaymentId(0)
                                    ->setMethod('cod'); //cod 是货到付款
$order->setPayment($orderPayment);


//遍历报价单中的项目,创建订单项目并将其添加到订单中,您只有一个产品,所以它只会添加一个订单项目。
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);
}

//设置总数
$subTotal = $quote->getGrandTotal();
$order->setSubtotal($subTotal)
        ->setBaseSubtotal($subTotal)
        ->setGrandTotal($subTotal)
        ->setBaseGrandTotal($subTotal);


//先下订单,然后保存。     
$transaction->addObject($order);
$transaction->addCommitCallback(array($order, 'place'));
$transaction->addCommitCallback(array($order, 'save'));
$事务->保存();
$quote->保存();

//清除会话和购物车。
Mage::getSingleton('checkout/session')->clear();
foreach($quote->getItemsCollection() as $_item)
{
     Mage::getSingleton('checkout/cart')->removeItem($_item->getId())->save();
}

//将用户重定向回你想要的位置。
于 2013-03-01T21:05:47.250 回答