/** * Returns the sku of the given item dependant on the product type. * * @param Mage_Sales_Model_Order_Item $item The item to return info from * @return String The sku */ protected function getItemSku($item) { if ($item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { return $item->getProductOptionByCode('simple_sku'); } return $item->getSku(); }
/** * Retrieves RMA item sku for backend * * @param Mage_Sales_Model_Order_Item $item * @return string */ public function getAdminProductSku($item) { $name = $item->getSku(); if ($item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { $productOptions = $item->getProductOptions(); return $productOptions['simple_sku']; } return $name; }
/** * Refund specific qty of order item * * @param Mage_Sales_Model_Order $order * @param Mage_Sales_Model_Order_Item $orderItem * @param $qtyToRefund * @return $this */ public function refundOrderItem(Mage_Sales_Model_Order $order, Mage_Sales_Model_Order_Item $orderItem, $qtyToRefund) { $cmModel = Mage::getSingleton('mageworx_orderspro/edit_creditmemo'); $cmModel->addItemToRefund($orderItem->getId(), $qtyToRefund); if ($orderItem->getProductType() == 'bundle') { $orderItem->setQtyRefunded($qtyToRefund); } return $this; }
/** * determine if the item's amounts should be put into the request. * * @param Mage_Sales_Model_Order_Item * @return bool */ protected function canIncludeAmounts(Mage_Sales_Model_Order_Item $item) { return !($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE && $item->isChildrenCalculated()); }
/** * Returns the name for a sales item. * Configurable products will have their chosen options added to their name. * Bundle products will have their chosen child product names added. * Grouped products will have their parents name prepended. * All others will have their own name only. * * @param Mage_Sales_Model_Order_Item $item the sales item model. * * @return string */ protected function buildItemName(Mage_Sales_Model_Order_Item $item) { $name = $item->getName(); $optNames = array(); if ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_SIMPLE) { /** @var Mage_Catalog_Model_Product_Type_Configurable $model */ $model = Mage::getModel('catalog/product_type_configurable'); $parentIds = $model->getParentIdsByChild($item->getProductId()); // If the product has a configurable parent, we assume we should tag // the parent. If there are many parent IDs, we are safer to tag the // products own name alone. if (count($parentIds) === 1) { $attributes = $item->getBuyRequest()->getData('super_attribute'); if (is_array($attributes)) { foreach ($attributes as $id => $value) { /** @var Mage_Catalog_Model_Resource_Eav_Attribute $attribute */ $attribute = Mage::getModel('catalog/resource_eav_attribute')->load($id); $label = $attribute->getSource()->getOptionText($value); if (!empty($label)) { $optNames[] = $label; } } } } } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { $opts = $item->getProductOptionByCode('attributes_info'); if (is_array($opts)) { foreach ($opts as $opt) { if (isset($opt['value']) && is_string($opt['value'])) { $optNames[] = $opt['value']; } } } } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) { $opts = $item->getProductOptionByCode('bundle_options'); if (is_array($opts)) { foreach ($opts as $opt) { if (isset($opt['value']) && is_array($opt['value'])) { foreach ($opt['value'] as $val) { $qty = ''; if (isset($val['qty']) && is_int($val['qty'])) { $qty .= $val['qty'] . ' x '; } if (isset($val['title']) && is_string($val['title'])) { $optNames[] = $qty . $val['title']; } } } } } } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_GROUPED) { $config = $item->getProductOptionByCode('super_product_config'); if (isset($config['product_id'])) { /** @var Mage_Catalog_Model_Product $parent */ $parent = Mage::getModel('catalog/product')->load($config['product_id']); $parentName = $parent->getName(); if (!empty($parentName)) { $name = $parentName . ' - ' . $name; } } } if (!empty($optNames)) { $name .= ' (' . implode(', ', $optNames) . ')'; } return $name; }
/** * Initialize creation data from existing order Item * * @param Mage_Sales_Model_Order_Item $orderItem * @param int $qty * @return Mage_Sales_Model_Quote_Item | string */ public function initFromOrderItem(Mage_Sales_Model_Order_Item $orderItem, $qty = null) { if (!$orderItem->getId()) { return $this; } $product = Mage::getModel('catalog/product')->setStoreId($this->getSession()->getStoreId())->load($orderItem->getProductId()); if ($product->getId()) { $product->setSkipCheckRequiredOption(true); $buyRequest = $orderItem->getBuyRequest(); if (is_numeric($qty)) { $buyRequest->setQty($qty); } $item = $this->getQuote()->addProduct($product, $buyRequest); if (is_string($item)) { return $item; } /*********************************************Set custom price selected starts************************************************************/ if (!$this->getSession()->getReordered() && $orderItem->getOriginalPrice() != $orderItem->getPrice()) { if ($orderItem->getProductType() == 'configurable' || $orderItem->getProductType() == 'bundle') { $productId = $orderItem->getProductId(); $quoteItemId = $orderItem->getQuoteItemId(); $items = $this->getQuote()->getItemsCollection(); foreach ($items as $item) { if ($item->getProduct()->getId() == $productId && !$item->getApplyPriceFlag()) { if ($orderItem->getOriginalPrice() != $orderItem->getPrice()) { $item->setCustomPrice($orderItem->getPrice())->setOriginalCustomPrice($orderItem->getPrice()); } //$item->setApplyPriceFlag(true); } } } else { $item->setCustomPrice($orderItem->getPrice())->setOriginalCustomPrice($orderItem->getPrice()); } } /*********************************************Set custom price selected ends************************************************************/ if ($additionalOptions = $orderItem->getProductOptionByCode('additional_options')) { $item->addOption(new Varien_Object(array('product' => $item->getProduct(), 'code' => 'additional_options', 'value' => serialize($additionalOptions)))); } Mage::dispatchEvent('sales_convert_order_item_to_quote_item', array('order_item' => $orderItem, 'quote_item' => $item)); return $item; } return $this; }
/** * get the correct order item * @param Mage_Sales_Model_Order_Item * @return Mage_Sales_Model_Order_Item */ protected function getItemForLookup(Mage_Sales_Model_Order_Item $item) { if ($item->getProductType() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { $item = reset($item->getChildrenItems()); } return $item; }
/** * Get the product the item represents. * * @param Mage_Sales_Model_Order_Item * @return Mage_Catalog_Model_Product */ protected function getItemProduct(Mage_Sales_Model_Order_Item $item) { // When dealing with configurable items, need to get tax data from // the child product and not the parent. if ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE) { $sku = $item->getSku(); $children = $item->getChildrenItems(); if ($children) { /** @var Mage_Sales_Model_Order_Item $childItem */ foreach ($children as $childItem) { $childProduct = $childItem->getProduct(); // If the SKU of the child product matches the SKU of the // item, the simple product being ordered was found and should // be used. if ($childProduct->getSku() === $sku) { return $childProduct; } } } } return $item->getProduct() ?: Mage::getModel('catalog/product')->load($item->getProductId()); }
/** * @param Mage_Sales_Model_Order_Item $orderItem * * @return bool */ public function isCanRenderOrderItem(Mage_Sales_Model_Order_Item $orderItem) { $notAllowedProductTypes = array(Mage_Catalog_Model_Product_Type_Configurable::TYPE_CODE, 'bundle'); if (in_array($orderItem->getProductType(), $notAllowedProductTypes)) { return false; } return true; }