/**
  * Add filter by attribute price
  *
  * @param Mage_CatalogSearch_Model_Advanced $object
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @param string|array $value
  */
 public function addPriceFilter($object, $attribute, $value)
 {
     if (empty($value['from']) && empty($value['to'])) {
         return false;
     }
     if (Mage::helper('solr')->isEnabled()) {
         $typeConverter = new DMC_Solr_Model_SolrServer_Adapter_Product_TypeConverter();
         $code = $attribute->getAttributeCode();
         $items = $typeConverter->getItems();
         $select = $object->getProductCollection()->getSelect();
         $rate = 1;
         if (!empty($value['currency'])) {
             $rate = Mage::app()->getStore()->getBaseCurrency()->getRate($value['currency']);
         }
         if (strlen($value['from']) > 0) {
             $from = $value['from'] * $rate;
         } else {
             $from = 0;
         }
         if (strlen($value['to']) > 0) {
             $to = $value['to'] * $rate;
         } else {
             $to = 99999999;
         }
         $select->where($items[$attribute->getFrontend()->getInputType()]['solr_index_prefix'] . $typeConverter::SUBPREFIX_INDEX . 'price:[' . $from . ' TO ' . $to . ']');
     } else {
         $adapter = $this->_getReadAdapter();
         $conditions = array();
         if (strlen($value['from']) > 0) {
             $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s >= ?', $value['from']);
         }
         if (strlen($value['to']) > 0) {
             $conditions[] = $adapter->quoteInto('price_index.min_price %s * %s <= ?', $value['to']);
         }
         if (!$conditions) {
             return false;
         }
         $object->getProductCollection()->addPriceData();
         $select = $object->getProductCollection()->getSelect();
         $response = $this->_dispatchPreparePriceEvent($select);
         $additional = join('', $response->getAdditionalCalculations());
         $rate = 1;
         if (!empty($value['currency'])) {
             $rate = Mage::app()->getStore()->getBaseCurrency()->getRate($value['currency']);
         }
         foreach ($conditions as $condition) {
             $select->where(sprintf($condition, $additional, $rate));
         }
     }
     return true;
 }
 /**
  * Return Product Attribute Store Label
  * Set attribute name like frontend lable for custom attributes (which wasn't defined by Google)
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @param int $storeId Store View Id
  * @return string Attribute Store View Label or Attribute code
  */
 public function getAttributeLabel($attribute, $storeId)
 {
     $attributeId = $attribute->getId();
     $frontendLabel = $attribute->getFrontend()->getLabel();
     if (is_array($frontendLabel)) {
         $frontendLabel = array_shift($frontendLabel);
     }
     if (!isset($this->_attributeLabels[$attributeId])) {
         $this->_attributeLabels[$attributeId] = $attribute->getStoreLabels();
     }
     if (isset($this->_attributeLabels[$attributeId][$storeId])) {
         return $this->_attributeLabels[$attributeId][$storeId];
     } else {
         if (!empty($frontendLabel)) {
             return $frontendLabel;
         } else {
             return $attribute->getAttributeCode();
         }
     }
 }
 /**
  * Return Product Attribute Store Label
  *
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @param int $storeId Store View Id
  * @return string Attribute Store View Label or Attribute code
  */
 protected function _getAttributeLabel($attribute, $storeId)
 {
     $frontendLabel = $attribute->getFrontend()->getLabel();
     if (is_array($frontendLabel)) {
         $frontendLabel = array_shift($frontendLabel);
     }
     if (!$this->_translations) {
         $moduleName = Mage_Catalog_Model_Entity_Attribute::MODULE_NAME;
         $separator = Mage_Core_Model_Translate::SCOPE_SEPARATOR;
         $this->_translations = Mage::getModel('core/translate_string')->load($moduleName . $separator . $frontendLabel)->getStoreTranslations();
     }
     if (isset($this->_translations[$storeId])) {
         return $this->_translations[$storeId];
     } else {
         return $attribute->getAttributeCode();
     }
 }
Exemple #4
0
 /**
  * Retrieve Product Attribute Value
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return string
  */
 public function getProductAttributeValue($product, $attribute)
 {
     if (!$product->hasData($attribute->getAttributeCode())) {
         return Mage::helper('Mage_Catalog_Helper_Data')->__('N/A');
     }
     if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), array('select', 'boolean', 'multiselect'))) {
         //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode()));
         $value = $attribute->getFrontend()->getValue($product);
     } else {
         $value = $product->getData($attribute->getAttributeCode());
     }
     return (string) $value == '' ? Mage::helper('Mage_Catalog_Helper_Data')->__('No') : $value;
 }
 /**
  * Retrieve Product Attribute Value
  *
  * @param Mage_Catalog_Model_Product $product
  * @param Mage_Catalog_Model_Resource_Eav_Attribute $attribute
  * @return string
  */
 public function getProductAttributeValue($product, $attribute)
 {
     if (!$product->hasData($attribute->getAttributeCode())) {
         return '&nbsp;';
     }
     if ($attribute->getSourceModel() || in_array($attribute->getFrontendInput(), array('select', 'boolean', 'multiselect'))) {
         //$value = $attribute->getSource()->getOptionText($product->getData($attribute->getAttributeCode()));
         $value = $attribute->getFrontend()->getValue($product);
     } else {
         $value = $product->getData($attribute->getAttributeCode());
     }
     return $value ? $value : '&nbsp;';
 }
 protected function getValueOrValueText(Mage_Catalog_Model_Product $product, $name, Mage_Catalog_Model_Resource_Eav_Attribute $resource)
 {
     $value_text = $product->getAttributeText($name);
     if (!$value_text) {
         $value_text = $resource->getFrontend()->getValue($product);
     }
     return $value_text;
 }