2011-11-08 27 views
5

Dường như không có sự nhất trí vững chắc về chủ đề này. Có một chủ đề on the Magento message board cung cấp tất cả các loại biến thể và phương pháp tiếp cận, không có loại nào phù hợp với tôi và không có cách nào giải thích những gì nên được thực hiện trong quy trình này. Từ những gì tôi có thể nói, bạn cần mô phỏng các bước của đơn đặt hàng được tạo trên trang web, nghĩa là thêm sản phẩm vào 'giỏ hàng', thêm địa chỉ giao hàng và thanh toán, thêm phương thức giao hàng, thêm phương thức thanh toán và 'checkout'.Làm cách nào để tôi có thể nhập lệnh vào Magento một cách có lập trình?

Ai đó có thể vui lòng giải thích chính xác các bước này và hiển thị các dòng mã có trách nhiệm thực hiện các bước.

Ngoài ra, tôi đã thấy tham chiếu trong các ví dụ về mã bảng thông báo của 'giỏ hàng' và 'báo giá'. Vui lòng giải thích sự khác biệt (hoặc điểm giống nhau) giữa 2.

+0

Tôi đã hỏi một câu hỏi hợp lệ. Tại sao bạn sẽ lãng phí thời gian của bạn gửi bài crap này? Và ai hạ gục bình chọn câu hỏi của tôi ???? – Billy

+0

Quan điểm của tôi là ai đó sẽ phải viết tương đương với một bài viết trên blog để trả lời đầy đủ mọi thứ bạn yêu cầu trong câu hỏi của bạn. Hơn nữa, viết một câu duy nhất thực sự không mất nhiều thời gian của tôi. Trên trang web này, một câu hỏi thường không nên yêu cầu một câu trả lời mất hơn 30 phút để viết. –

+0

Tôi trả lời một nửa câu hỏi của mình trong 10 phút đánh máy. – Billy

Trả lời

6

Tôi đã sắp xếp công việc lập trình. Nó chỉ ra bạn không cần phải mô phỏng 'thêm vào giỏ hàng' như các bài viết khác ở nơi khác đề nghị. Bạn có thể tạo đối tượng thứ tự và các đối tượng liên quan và điền dữ liệu, nó không đơn giản như tôi muốn.

Tạo đơn đặt hàng được mô tả rõ nhất theo số this blog post.

tôi đã sao chép đoạn code ở đây:

$id=1; // get Customer Id 
$customer = Mage::getModel('customer/customer')->load($id); 

$transaction = Mage::getModel('core/resource_transaction'); 
$storeId = $customer->getStoreId(); 
$reservedOrderId = Mage::getSingleton('eav/config')->getEntityType('order')->fetchNewIncrementId($storeId); 

$order = Mage::getModel('sales/order') 
    ->setIncrementId($reservedOrderId) 
    ->setStoreId($storeId) 
    ->setQuoteId(0) 
    ->setGlobal_currency_code('USD') 
    ->setBase_currency_code('USD') 
    ->setStore_currency_code('USD') 
    ->setOrder_currency_code('USD'); 

// set Customer data 
$order->setCustomer_email($customer->getEmail()) 
    ->setCustomerFirstname($customer->getFirstname()) 
    ->setCustomerLastname($customer->getLastname()) 
    ->setCustomerGroupId($customer->getGroupId()) 
    ->setCustomer_is_guest(0) 
    ->setCustomer($customer); 

// set Billing Address 
$billing = $customer->getDefaultBillingAddress(); 
$billingAddress = Mage::getModel('sales/order_address') 
    ->setStoreId($storeId) 
    ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_BILLING) 
    ->setCustomerId($customer->getId()) 
    ->setCustomerAddressId($customer->getDefaultBilling()) 
    ->setCustomer_address_id($billing->getEntityId()) 
    ->setPrefix($billing->getPrefix()) 
    ->setFirstname($billing->getFirstname()) 
    ->setMiddlename($billing->getMiddlename()) 
    ->setLastname($billing->getLastname()) 
    ->setSuffix($billing->getSuffix()) 
    ->setCompany($billing->getCompany()) 
    ->setStreet($billing->getStreet()) 
    ->setCity($billing->getCity()) 
    ->setCountry_id($billing->getCountryId()) 
    ->setRegion($billing->getRegion()) 
    ->setRegion_id($billing->getRegionId()) 
    ->setPostcode($billing->getPostcode()) 
    ->setTelephone($billing->getTelephone()) 
    ->setFax($billing->getFax()); 
$order->setBillingAddress($billingAddress); 

$shipping = $customer->getDefaultShippingAddress(); 
$shippingAddress = Mage::getModel('sales/order_address') 
    ->setStoreId($storeId) 
    ->setAddressType(Mage_Sales_Model_Quote_Address::TYPE_SHIPPING) 
    ->setCustomerId($customer->getId()) 
    ->setCustomerAddressId($customer->getDefaultShipping()) 
    ->setCustomer_address_id($shipping->getEntityId()) 
    ->setPrefix($shipping->getPrefix()) 
    ->setFirstname($shipping->getFirstname()) 
    ->setMiddlename($shipping->getMiddlename()) 
    ->setLastname($shipping->getLastname()) 
    ->setSuffix($shipping->getSuffix()) 
    ->setCompany($shipping->getCompany()) 
    ->setStreet($shipping->getStreet()) 
    ->setCity($shipping->getCity()) 
    ->setCountry_id($shipping->getCountryId()) 
    ->setRegion($shipping->getRegion()) 
    ->setRegion_id($shipping->getRegionId()) 
    ->setPostcode($shipping->getPostcode()) 
    ->setTelephone($shipping->getTelephone()) 
->setFax($shipping->getFax()); 

$order->setShippingAddress($shippingAddress) 
    ->setShipping_method('flatrate_flatrate') 
    ->setShippingDescription($this->getCarrierName('flatrate')); 

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

// let say, we have 2 products 
$subTotal = 0; 
    $products = array(
    '1001' => array(
    'qty' => 1 
), 
    '1002' ->array(
    'qty' => 3 
), 
); 
foreach ($products as $productId=>$product) { 
    $_product = Mage::getModel('catalog/product')->load($productId); 
    $rowTotal = $_product->getPrice() * $product['qty']; 
    $orderItem = Mage::getModel('sales/order_item') 
    ->setStoreId($storeId) 
    ->setQuoteItemId(0) 
    ->setQuoteParentItemId(NULL) 
    ->setProductId($productId) 
    ->setProductType($_product->getTypeId()) 
    ->setQtyBackordered(NULL) 
    ->setTotalQtyOrdered($product['rqty']) 
    ->setQtyOrdered($product['qty']) 
    ->setName($_product->getName()) 
    ->setSku($_product->getSku()) 
    ->setPrice($_product->getPrice()) 
    ->setBasePrice($_product->getPrice()) 
    ->setOriginalPrice($_product->getPrice()) 
    ->setRowTotal($rowTotal) 
    ->setBaseRowTotal($rowTotal); 

    $subTotal += $rowTotal; 
    $order->addItem($orderItem); 
} 

$order->setSubtotal($subTotal) 
    ->setBaseSubtotal($subTotal) 
    ->setGrandTotal($subTotal) 
    ->setBaseGrandTotal($subTotal); 

$transaction->addObject($order); 
$transaction->addCommitCallback(array($order, 'place')); 
$transaction->addCommitCallback(array($order, 'save')); 
$transaction->save(); 

tôi vẫn chưa nhận được một sự hiểu biết về sự khác biệt giữa một chiếc xe và báo giá là.

Các vấn đề liên quan