0

注文を2つの異なる部分(1つはダウンロード可能、もう1つは物理的)に分割し、一度に合計金額を承認して、注文時にダウンロード可能な製品の量を取得し、製品の準備ができている間に管理パネルから手動で取得する方法出荷用。

誰か助けてくれませんか............。

よろしくお願いします:D

4

1 に答える 1

1

OnePageControllerメソッドの下で(Onepageチェックアウトを使用している場合)カスタムイベントを作成する必要がありますsaveOrderAction()

次のコードを使用して、現在のカートから商品を削除し、物理的な商品の新しい注文を作成します。

class CompanyName_ModuleName_Model_Order extends Mage_Core_Model_Abstract {

public function createOrder() {

    $quoteID = Mage::getSingleton("checkout/session")->getQuote()->getId();
    $quote = Mage::getModel("sales/quote")->load($quoteID);

    foreach($quote->getAllItems() as $item){
        $itemId = $item->getId();
        $productId = $item->getProductId();
        if(put your condition here){
            /* remove the item fro which need to split the order */
            $quote->removeItem($itemId)->save();
        }
    }

    $id = Mage::getSingleton('customer/session')->getCustomer()->getId();
    $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('freeshipping')
            ->setShippingDescription('Free Shipping - Free');
    /*set payment details here for example */
    $orderPayment = Mage::getModel('sales/order_payment')
                    ->setStoreId($storeId)
                    ->setCustomerPaymentId(0)
                    ->setMethod('cybersource_soap')
                    ->setCcType('VI')
                    ->setCcNumber('4111111111111111')
                    ->setCcLast4('1111')
                    ->setCcExpMonth('2')
                    ->setCcExpYear('2013')
                    ->setCcCid('123');
    $order->setPayment($orderPayment);

    /* let say, we have 2 products */
    $subTotal = 0;
    /* pass the product id and quantity here e.g. */
    $products = array(
    '2' => array(
    'qty' => 1
    )
    );
    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['qty'])
                        ->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();
}

}

設定などに応じてこのコードを変更することを忘れないでください。

于 2012-12-20T13:51:50.407 に答える