Skip to content

Commit

Permalink
implemented EAV Cache
Browse files Browse the repository at this point in the history
  • Loading branch information
sqlexception committed Sep 21, 2018
1 parent c93e134 commit d5b5f41
Show file tree
Hide file tree
Showing 10 changed files with 417 additions and 309 deletions.
3 changes: 1 addition & 2 deletions app/code/core/Mage/Catalog/Helper/Data.php
Original file line number Diff line number Diff line change
Expand Up @@ -422,8 +422,7 @@ public function canApplyMsrpToProductType($product)
{
if($this->_mapApplyToProductType === null) {
/** @var $attribute Mage_Catalog_Model_Resource_Eav_Attribute */
$attribute = Mage::getModel('catalog/resource_eav_attribute')
->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'msrp_enabled');
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY,'msrp_enabled');
$this->_mapApplyToProductType = $attribute->getApplyTo();
}
return empty($this->_mapApplyToProductType) || in_array($product->getTypeId(), $this->_mapApplyToProductType);
Expand Down
4 changes: 2 additions & 2 deletions app/code/core/Mage/Catalog/Model/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,8 +256,8 @@ public function getSourceOptionId($source, $value)
*/
public function getProductAttributes()
{
if (is_null($this->_productAttributes)) {
$this->_productAttributes = array_keys($this->getAttributesUsedInProductListing());
if (null === $this->_usedInProductListing) {
$this->_usedInProductListing = Mage::getSingleton('eav/config')->getAttributesUsedInProductListing();
}
return $this->_productAttributes;
}
Expand Down
25 changes: 10 additions & 15 deletions app/code/core/Mage/Catalog/Model/Layer.php
Original file line number Diff line number Diff line change
Expand Up @@ -214,24 +214,19 @@ public function getCurrentStore()
*/
public function getFilterableAttributes()
{
// $entity = Mage::getSingleton('eav/config')
// ->getEntityType('catalog_product');

$setIds = $this->_getSetIds();
if (!$setIds) {
if (false === is_array($setIds) || count($setIds) === 0) {
return array();
}
/** @var $collection Mage_Catalog_Model_Resource_Product_Attribute_Collection */
$collection = Mage::getResourceModel('catalog/product_attribute_collection');
$collection
->setItemObjectClass('catalog/resource_eav_attribute')
->setAttributeSetFilter($setIds)
->addStoreLabel(Mage::app()->getStore()->getId())
->setOrder('position', 'ASC');
$collection = $this->_prepareAttributeCollection($collection);
$collection->load();

return $collection;
/** @var Mage_Eav_Model_Config $eavConfig */
$attributes = Mage::getSingleton('eav/config')->getFilterableProductAttributesUsedInSets($setIds);
usort($attributes, function ($attributeA, $attributeB){
if ((int)$attributeA->getPosition() == (int)$attributeB->getPosition()) {
return 0;
}
return ((int)$attributeA->getPosition() < (int)$attributeB->getPosition()) ? -1 : 1;
});
return $attributes;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -270,8 +270,7 @@ protected function _getLoadGallerySelect(array $productIds, $storeId, $attribute
*/
protected function _getAttributeId() {
if(is_null($this->_attributeId)) {
$attribute = Mage::getModel('eav/entity_attribute')
->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'media_gallery');
$attribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'media_gallery');

$this->_attributeId = $attribute->getId();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function getTierPriceAttribute()
{
$data = $this->getData('tier_price_attribute');
if (is_null($data)) {
$data = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'tier_price');
$data = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'tier_price');
$this->setData('tier_price_attribute', $data);
}
return $data;
Expand All @@ -75,7 +75,7 @@ public function getPriceAttribute()
{
$data = $this->getData('price_attribute');
if (is_null($data)) {
$data = Mage::getModel('eav/entity_attribute')->loadByCode(Mage_Catalog_Model_Product::ENTITY, 'price');
$data = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, 'price');
$this->setData('price_attribute', $data);
}
return $data;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ public function getPurchasedSeparatelyAttribute()
if (is_null($this->_purchasedSeparatelyAttribute)) {
$_attributeCode = 'links_purchased_separately';

$this->_purchasedSeparatelyAttribute = Mage::getModel('eav/entity_attribute')
->loadByCode(Mage_Catalog_Model_Product::ENTITY, $_attributeCode);
$this->_purchasedSeparatelyAttribute = Mage::getSingleton('eav/config')->getAttribute(Mage_Catalog_Model_Product::ENTITY, $_attributeCode);
}

return $this->_purchasedSeparatelyAttribute;
Expand Down
Loading

0 comments on commit d5b5f41

Please sign in to comment.