Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function _productToOrderItem(Mage_Catalog_Model_Product $product, $qty = 1, $price)
- {
- if($price){
- $finalPrice = $price;
- }else{
- $finalPrice = $product->getFinalPrice();
- }
- $rowTotal = $finalPrice * $qty;
- $options = $product->getCustomOptions();
- $optionsByCode = array();
- $bundleOptSelAttr = null;
- foreach ($options as $option)
- {
- $quoteOption = Mage::getModel('sales/quote_item_option')->setData($option->getData())
- ->setProduct($option->getProduct());
- if($quoteOption->getCode() == 'bundle_selection_attributes' ) {
- $bundleOptSelAttr = $quoteOption->getValue();
- }
- $optionsByCode[$quoteOption->getCode()] = $quoteOption;
- }
- $product->setCustomOptions($optionsByCode);
- $stockItem =Mage::getModel('cataloginventory/stock_item')->loadByProduct( $product->getId() );
- if( $stockItem->getManageStock() ){
- $stockItem->setData('qty', $stockItem->getQty()-$product['qty']);
- }
- $stockItem->save();
- $options = $product->getTypeInstance(true)->getOrderOptions($product);
- if($bundleOptSelAttr != null) {
- $options['bundle_selection_attributes'] = $bundleOptSelAttr;
- }
- $orderItem = Mage::getModel('sales/order_item')
- ->setStoreId($this->_storeId)
- ->setQuoteItemId(0)
- ->setQuoteParentItemId(NULL)
- ->setProductId($product->getId())
- ->setProductType($product->getTypeId())
- ->setQtyBackordered(NULL)
- ->setTotalQtyOrdered($product['rqty'])
- ->setQtyOrdered($product['qty'])
- ->setName($product->getName())
- ->setSku($product->getSku())
- ->setPrice( $finalPrice )
- ->setBasePrice( $finalPrice )
- ->setOriginalPrice( $finalPrice )
- ->setRowTotal($rowTotal)
- ->setBaseRowTotal($rowTotal)
- ->setWeeeTaxApplied(serialize(array()))
- ->setBaseWeeeTaxDisposition(0)
- ->setWeeeTaxDisposition(0)
- ->setBaseWeeeTaxRowDisposition(0)
- ->setWeeeTaxRowDisposition(0)
- ->setBaseWeeeTaxAppliedAmount(0)
- ->setBaseWeeeTaxAppliedRowAmount(0)
- ->setWeeeTaxAppliedAmount(0)
- ->setWeeeTaxAppliedRowAmount(0)
- ->setProductOptions($options);
- $this->_subTotal += $rowTotal;
- return $orderItem;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement