Esempio n. 1
0
 /**
  * Add custom attributes selected by magento admin to query
  *
  * @param Varien_Data_Collection_Db $collection Collection of data which will be spit out as feed
  * @param string $customAttribs Comma separated list of attribute codes
  * @param array $fieldMap Reference to fieldmap where attribute codes should also be added
  */
 protected function addCustomAttributes($collection, $customAttribs, &$fieldMap)
 {
     // Log
     Mage::helper('mybuys')->log("Adding custom attributes include in query: {$customAttribs}", Zend_Log::INFO, Mybuys_Connector_Helper_Data::LOG_FILE);
     // Check if we have any custom attribs
     if (strlen(trim($customAttribs)) > 0) {
         // Iterate custom attribs
         foreach (explode(',', $customAttribs) as $curAttrib) {
             // Trim attribute code
             $curAttrib = trim($curAttrib);
             // Check if attribute exists
             $_attribute = $collection->getAttribute($curAttrib);
             if ($_attribute === false) {
                 // Attribute not found
                 Mage::throwException("Attribte not found: {$curAttrib}");
             }
             // Log
             Mage::helper('mybuys')->log("Adding attribute to query: {$curAttrib}", Zend_Log::DEBUG, Mybuys_Connector_Helper_Data::LOG_FILE);
             if ($_attribute->getFrontendInput() == "select" || $_attribute->getFrontendInput() == "multiselect") {
                 // attribute is a select of multi-select input and attribute id to value translation is needed
                 // Log
                 Mage::helper('mybuys')->log("Note - Attribute needs translation", Zend_Log::DEBUG, Mybuys_Connector_Helper_Data::LOG_FILE);
                 $this->_optionValueMap['custom_' . $curAttrib] = true;
             }
             // Add attribute to select
             $collection->addExpressionAttributeToSelect('custom_' . $curAttrib, "{{" . $curAttrib . "}}", $curAttrib)->addAttributeToSelect($curAttrib);
             // Add attribute to map
             $fieldMap['custom_' . $curAttrib] = 'custom_' . $curAttrib;
         }
     }
     // Return the original collection object
     return $collection;
 }