SHARE
TWEET

Untitled

a guest Jul 4th, 2016 87 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.    function _productToOrderItem(Mage_Catalog_Model_Product $product, $qty = 1, $price)
  2.     {
  3.         if($price){
  4.             $finalPrice = $price;
  5.         }else{
  6.             $finalPrice = $product->getFinalPrice();
  7.         }
  8.  
  9.         $rowTotal = $finalPrice * $qty;
  10.  
  11.         $options = $product->getCustomOptions();
  12.  
  13.         $optionsByCode = array();
  14.         $bundleOptSelAttr = null;
  15.         foreach ($options as $option)
  16.         {
  17.             $quoteOption = Mage::getModel('sales/quote_item_option')->setData($option->getData())
  18.                 ->setProduct($option->getProduct());
  19.  
  20.             if($quoteOption->getCode() ==  'bundle_selection_attributes' ) {
  21.                 $bundleOptSelAttr = $quoteOption->getValue();
  22.             }
  23.             $optionsByCode[$quoteOption->getCode()] = $quoteOption;
  24.         }
  25.  
  26.         $product->setCustomOptions($optionsByCode);
  27.  
  28.         $stockItem =Mage::getModel('cataloginventory/stock_item')->loadByProduct( $product->getId() );
  29.         if( $stockItem->getManageStock() ){
  30.             $stockItem->setData('qty', $stockItem->getQty()-$product['qty']);
  31.         }
  32.         $stockItem->save();
  33.  
  34.         $options = $product->getTypeInstance(true)->getOrderOptions($product);
  35.        
  36.         if($bundleOptSelAttr != null) {
  37.             $options['bundle_selection_attributes'] = $bundleOptSelAttr;
  38.         }
  39.         $orderItem = Mage::getModel('sales/order_item')
  40.             ->setStoreId($this->_storeId)
  41.             ->setQuoteItemId(0)
  42.             ->setQuoteParentItemId(NULL)
  43.             ->setProductId($product->getId())
  44.             ->setProductType($product->getTypeId())
  45.             ->setQtyBackordered(NULL)
  46.             ->setTotalQtyOrdered($product['rqty'])
  47.             ->setQtyOrdered($product['qty'])
  48.             ->setName($product->getName())
  49.             ->setSku($product->getSku())
  50.             ->setPrice( $finalPrice )
  51.             ->setBasePrice( $finalPrice )
  52.             ->setOriginalPrice( $finalPrice )
  53.             ->setRowTotal($rowTotal)
  54.             ->setBaseRowTotal($rowTotal)
  55.  
  56.             ->setWeeeTaxApplied(serialize(array()))
  57.             ->setBaseWeeeTaxDisposition(0)
  58.             ->setWeeeTaxDisposition(0)
  59.             ->setBaseWeeeTaxRowDisposition(0)
  60.             ->setWeeeTaxRowDisposition(0)
  61.             ->setBaseWeeeTaxAppliedAmount(0)
  62.             ->setBaseWeeeTaxAppliedRowAmount(0)
  63.             ->setWeeeTaxAppliedAmount(0)
  64.             ->setWeeeTaxAppliedRowAmount(0)
  65.  
  66.             ->setProductOptions($options);
  67.  
  68.         $this->_subTotal += $rowTotal;
  69.  
  70.         return $orderItem;
  71.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top