1

有没有一种方法可以在 Magento 中使用订单中定义的“自定义”产品创建订单。该订单不需要创建自定义产品。这些自定义产品将在创建订单时确定自定义价格和自定义产品标题。

因此,在创建订单时,我只需指定一些带有价格的自定义产品,然后将它们添加到订单中。

同样,产品不会在 Magento 中的任何地方定义,所以我只想说,我想在 9.99 处添加 xyz,在 1.99 处添加 zxy,也许我想在 3.99 处添加另一个 xyz。

订单将显示为,

xyz | 9.99

zxy | 1.99

xyz | 3.99

总计 | 15.97

4

1 回答 1

3

以编程方式创建带有自定义产品的订单是可能的,这是一个示例代码:

<?php
require_once 'app/Mage.php';
umask(0);
Mage::app('admin');

$order = create();
echo $order;

function create()
{


        $storeId = 1;
        if (!$storeId) {
            $storeIds = Mage::app()->getWebsite($customer->getWebsiteId())->getStoreIds();
            reset($storeIds);
            $storeId = current($storeIds);
        }

        $order = Mage::getModel('sales/order')
                ->setState('new');

        $orderPayment = Mage::getModel('sales/order_payment')
              ->setStoreId($storeId)
              ->setCustomerPaymentId(0)
              ->setMethod('checkmo')
              ->setPo_number(' - ');
            $order->setPayment($orderPayment);

        $billingAddress = Mage::getModel('sales/order_address');
        $shippingAddress = Mage::getModel('sales/order_address');


        $order->setStoreId($storeId)
              ->setQuoteId(0)
              ->setGlobal_currency_code('EUR')
              ->setBase_currency_code('EUR')
              ->setStore_currency_code('EUR')
              ->setOrder_currency_code('EUR')
              ->setStatus($orderData['status']);

              // set Customer data
              $order->setCustomer_email('a@b.com')
              ->setCustomerFirstname('firstname')
              ->setCustomerLastname('lastname')
              ->setCustomer_is_guest(1);

              // set Billing Address
              $billingAddress
              ->setStoreId($storeId)
              ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING)
              ->setPrefix('mr')
              ->setFirstname('firstname')
              ->setLastname('lastname')
              ->setCompany('company')
              ->setStreet('street')
              ->setCity('city')
              ->setCountry_id('US')
              ->setPostcode('12345');

              $order->setBillingAddress($billingAddress);

              $shippingAddress
              ->setStoreId($storeId)
              ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING)
              ->setPrefix('mr')
              ->setFirstname('firstname')
              ->setLastname('lastname')
              ->setCompany('company')
              ->setStreet('street')
              ->setCity('city')
              ->setCountry_id('US')
              ->setPostcode('12345');


              $order->setShippingAddress($shippingAddress)
              ->setShipping_method('freeshipping_freeshipping')
              ->setShippingDescription('Free Shipping - Free');


                $orderItem = Mage::getModel('sales/order_item')
                    ->setStoreId(1)
                    ->setQuoteItemId(0)
                    ->setQuoteParentItemId(NULL)
                    ->setQtyBackordered(NULL)
                    ->setTotalQtyOrdered(10)
                    ->setQtyOrdered(10)
                    ->setName('custom product name')
                    ->setPrice(100)
                    ->setBasePrice(10)
                    ->setOriginalPrice(10)
                    ->setRowTotal(1000)
                    ->setBaseRowTotal(1000);

                    $order->addItem($orderItem);


                $order->setSubtotal(2000)
                    ->setSubtotalIncludingTax(2000)
                    ->setBaseSubtotal(2000)
                    ->setGrandTotal(2000)
                    ->setBaseGrandTotal(2000)
                    ->setTaxAmount(0)
                    ->setTotalQtyOrdered(10);

              $order->save();


    return $order;
}

?>

于 2013-02-06T11:32:17.427 回答