/** * Returns the name for a quote 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 parent product name prepended. * All others will have their own name only. * * @param Mage_Sales_Model_Quote_Item $item the quote item model. * * @return string */ public function getProductName($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) { /* @var $helper Mage_Catalog_Helper_Product_Configuration */ $helper = Mage::helper('catalog/product_configuration'); foreach ($helper->getConfigurableOptions($item) as $opt) { if (isset($opt['value']) && is_string($opt['value'])) { $optNames[] = $opt['value']; } } } elseif ($item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_BUNDLE) { $type = $item->getProduct()->getTypeInstance(true); $opts = $type->getOrderOptions($item->getProduct()); if (isset($opts['bundle_options']) && is_array($opts['bundle_options'])) { foreach ($opts['bundle_options'] 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->getBuyRequest()->getData('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; }
/** * @param Mage_Sales_Model_Quote_Item $quoteItem * @return Adyen_Subscription_Model_Product_Subscription */ protected function _getProductSubscription(Mage_Sales_Model_Quote_Item $quoteItem) { $subscriptionId = $quoteItem->getBuyRequest()->getData('adyen_subscription'); if (!$subscriptionId) { return false; } $subscriptionProductSubscription = Mage::getModel('adyen_subscription/product_subscription')->load($subscriptionId); if (!$subscriptionProductSubscription->getId()) { return false; } Mage::dispatchEvent('adyen_subscription_quote_getproductsubscription', array('productSubscription' => $subscriptionProductSubscription, 'item' => $quoteItem)); return $subscriptionProductSubscription; }