/** * @param Varien_Db_Select $select * @param string $attributeCode * @return $this */ public function joinAttribute($select, $attributeCode) { /* @var $core Mana_Core_Helper_Data */ $core = Mage::helper(strtolower('Mana_Core')); /* @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */ $attribute = $core->collectionFind($this->getAttributes(), 'attribute_code', $attributeCode); /* @var $db Varien_Db_Adapter_Pdo_Mysql */ $db = $select->getAdapter(); $alias = 'meav_' . $attributeCode; $storeAlias = 's' . $alias; $from = $select->getPart(Varien_Db_Select::FROM); if (!isset($from[$alias])) { $select->joinLeft(array($alias => $attribute->getBackendTable()), implode(' AND ', array("`{$alias}`.`entity_id` = `e`.`entity_id`", $db->quoteInto("`{$alias}`.`attribute_id` = ?", $attribute->getId()), "`{$alias}`.`store_id` = 0")), null); $select->joinLeft(array($storeAlias => $attribute->getBackendTable()), implode(' AND ', array("`{$storeAlias}`.`entity_id` = `e`.`entity_id`", $db->quoteInto("`{$storeAlias}`.`attribute_id` = ?", $attribute->getId()), $db->quoteInto("`{$storeAlias}`.`store_id` = ?", Mage::app()->getStore()->getId()))), null); } return $this; }
/** * Join tax class * @param Varien_Db_Select $select * @param int $storeId * @param string $priceTable * @return Mage_Tax_Helper_Data */ public function joinTaxClass($select, $storeId, $priceTable = 'main_table') { $taxClassAttribute = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'tax_class_id'); $joinConditionD = implode(' AND ', array("tax_class_d.entity_id = {$priceTable}.entity_id", $select->getAdapter()->quoteInto('tax_class_d.attribute_id = ?', (int) $taxClassAttribute->getId()), 'tax_class_d.store_id = 0')); $joinConditionC = implode(' AND ', array("tax_class_c.entity_id = {$priceTable}.entity_id", $select->getAdapter()->quoteInto('tax_class_c.attribute_id = ?', (int) $taxClassAttribute->getId()), $select->getAdapter()->quoteInto('tax_class_c.store_id = ?', (int) $storeId))); $select->joinLeft(array('tax_class_d' => $taxClassAttribute->getBackend()->getTable()), $joinConditionD, array())->joinLeft(array('tax_class_c' => $taxClassAttribute->getBackend()->getTable()), $joinConditionC, array()); return $this; }