/** * Spawn the correct validator object and init it * * @param $rulesConfig array * @param Mage_Sales_Model_Quote_Item $item * @return Jarlssen_CustomCartValidation_Model_Factory */ public function getRuleModels($rulesConfig, $item) { $ruleModels = array(); $productType = $item->getProductType(); foreach ($rulesConfig as $config) { if ('*' == $config['product_type'] || $config['product_type'] == $productType) { try { $ruleModel = Mage::getModel($config['model']); $ruleModel->setItem($item)->setCode($config['code'])->setOrigin($config['origin']); $ruleModels[] = $ruleModel; } catch (Exception $e) { Mage::logException($e); } } } return $ruleModels; }
/** * Get item row html * * @param Mage_Sales_Model_Quote_Item $item * @return string */ public function getItemHtml(Mage_Sales_Model_Quote_Item $item) { /** @var $renderer Mage_Checkout_Block_Cart_Item_Renderer */ $renderer = $this->getItemRenderer($item->getProductType())->setQtyMode(false); if ($item->getProductType() == 'undefined') { $renderer->overrideProductThumbnail($this->helper('catalog/image')->init($item, 'thumbnail')); $renderer->setProductName(''); } $renderer->setDeleteUrl($this->getUrl('checkout/cart/removeFailed', array('sku' => Mage::helper('core/url')->urlEncode($item->getSku())))); $renderer->setIgnoreProductUrl(!$this->showItemLink($item)); // Don't display subtotal column $item->setNoSubtotal(true); return parent::getItemHtml($item); }
/** * Get the unavailable item handler for the item. Handler based * on item product type. * * @param Mage_Sales_Model_Quote_Item * @return EbayEnterprise_Inventory_Model_Quantity_Unavailable_Item_IHandler */ protected function _getUnavailableHandlerForItem(Mage_Sales_Model_Quote_Item $item) { $configuredHandlers = $this->_config->unavailableItemHandlers; $productType = $item->getProductType(); $configuredHandler = $this->_loadConfiguredHandler($configuredHandlers, $productType) ?: $this->_loadConfiguredHandler($configuredHandlers, EbayEnterprise_Inventory_Model_Config::DEFAULT_UNAVAILABLE_ITEM_HANDLER_KEY); // If no useful specific or default instance is configured, go with this, // which should (as much as possible) be useful as a default implementation. return $configuredHandler ?: Mage::getModel('ebayenterprise_inventory/quantity_unavailable_item_default'); }
/** * Checks if item is configurable * * @param Mage_Sales_Model_Quote_Address_Item|Mage_Sales_Model_Quote_Item|Mage_Sales_Model_Order_Creditmemo_Item|Mage_Sales_Model_Order_Invoice_Item $item * @return bool */ protected function _isConfigurable($item) { if ($item instanceof Mage_Sales_Model_Quote_Item) { return $item->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE; } if ($item instanceof Mage_Sales_Model_Quote_Address_Item) { return $item->getProduct()->getTypeId() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE; } if ($item instanceof Mage_Sales_Model_Order_Invoice_Item || $item instanceof Mage_Sales_Model_Order_Creditmemo_Item) { return $item->getOrderItem()->getProductType() === Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE; } return false; }
/** * determines if we should skip the items with special price or other (in futeure) conditions * * @param Mage_Sales_Model_Quote_Item $item * @param Amasty_Promo_Model_Sales_Quote_Address $address * * @return bool */ protected function _skip($item, $address) { if (!Mage::getStoreConfig('ampromo/general/skip_special_price')) { return false; } if ($item->getProductType() == 'bundle') { return false; } if (is_null($this->_itemsWithDiscount) || count($this->_itemsWithDiscount) == 0) { $productIds = array(); $this->_itemsWithDiscount = array(); foreach ($this->_getAllItems($address) as $addressItem) { $productIds[] = $addressItem->getProductId(); } if (!$productIds) { return false; } $productsCollection = Mage::getModel('catalog/product')->getCollection()->addPriceData()->addAttributeToFilter('entity_id', array('in' => $productIds))->addAttributeToFilter('price', array('gt' => new Zend_Db_Expr('final_price'))); foreach ($productsCollection as $product) { $this->_itemsWithDiscount[] = $product->getId(); } } if (Mage::getStoreConfig('ampromo/general/skip_special_price_configurable')) { if ($item->getProductType() == "configurable") { foreach ($item->getChildren() as $child) { if (in_array($child->getProductId(), $this->_itemsWithDiscount)) { return true; } } } } if (!in_array($item->getProductId(), $this->_itemsWithDiscount)) { return false; } return true; }
/** * 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; }