0

I need to split order based on Vendor ID. I have COD and CC as two payment methods enabled in my site.

With COD order placing working fine and splitting also working fine. When I tried to place order with CC getting error Credit card number mismatch with credit card type and When I disable my module it is working fine.

Below is my code for splitting order

class PMTECH_Splitorder_Model_Checkout_Type_Onepage extends Mage_Checkout_Model_Type_Onepage {

    public function saveOrder() {
        $quote = $this->getQuote();

        //First build an array with the items split by attribute "flternow"
        $sortedItems = array();
        foreach ($quote->getAllItems() as $item) {
            $product = Mage::getModel('catalog/product')->load($item->getProduct()->getId());
            $sortedItems[$product->getUdropshipVendor()][] = $item; //array('product_id'=>$item->getProduct()->getId(),'qty'=>$item->getQty());
        }

        $allOrderId = '';
        foreach ($sortedItems as $seller => $items) {
            foreach ($quote->getAllItems() as $item) {
                $quote->getItemsCollection()->removeItemByKey($item->getId());
            }
            foreach ($items as $item) {
                $quote->getItemsCollection()->addItem($item);
            }
            // Update totals for seller
            $cart = Mage::getSingleton('checkout/session')->getQuote();
            foreach ($cart->getAllAddresses() as $address) {
                $address->unsetData('cached_items_all');
                $address->unsetData('cached_items_nonnominal');
                $address->unsetData('cached_items_nominal');
            }
            $address = $quote->getShippingAddress();
            $zipcode = $address->getPostcode();
            $country = $address->getCountry();

            // Update the cart's quote.
//            $ShipCart = Mage::getSingleton('checkout/cart');
//            $shipAddress = $ShipCart->getQuote()->getShippingAddress();
//            $shipAddress->setCountryId($country)->setPostcode($zipcode)->setCollectShippingrates(true);
//            $ShipCart->save();
            $cart->setTotalsCollectedFlag(false);
            $cart->collectTotals(); //echo 1 ;die;
            // Delegate to parent method to place an order for each seller
            parent::saveOrder();
            $lastOrderId = Mage::getSingleton('checkout/session')
                    ->getLastRealOrderId();
            // Mage::log($lastOrderId,NULL,'orderlist.log');
            if ($allOrderId == '') {
                $allOrderId = $allOrderId . $lastOrderId;
            } else {
                $allOrderId = $allOrderId . ', ' . $lastOrderId;
            }
        }
        $arr = explode(",", $allOrderId);
        $amount = $quote->getShippingAddress()->getShippingAmount();
        if (count($arr) > 1) {
            $order = Mage::getModel('sales/order')->load($lastOrderId, 'increment_id');
            $shippingprice = 0; //custom shipping price
            $order->setShippingAmount($shippingprice);
            $order->setBaseShippingAmount($shippingprice);
            $order->setGrandTotal($order->getGrandTotal() - $amount); //adding shipping price to grand total
            $order->save();
        }

        //Mage::log(count($arr)."===".$amount."===".$lastOrderId."====". $allOrderId, NULL, 'orderlist.log');
        Mage::getSingleton('core/session')->setCurrentAllOrderId($allOrderId);
        return $this;
    }

}

Can someone help me on this?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.