-
Notifications
You must be signed in to change notification settings - Fork 9.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
$productAttribute->getFrontend()->getSelectOptions() grabbing unnecessary options #293
Comments
Please check #90 for detailed discussion regarding this issue. |
The problem that this issue fixes is the number of super attributes returned by this line: Issue #90 does nothing to correct that. I'm assuming you may have run a similar test against this change (as in issue #90): How many super attributes did this test contain? Was each simple product completely unique in this test (therefore having 5,000 super attributes)? If you only had 2 super attributes to cover the 5,000 simple products, then this test would have (incorrectly) shown no improvements. If you have 5,000 super attributes, this call: is going to return 5,000 options causing the for loop (foreach ($options as $option)) to run 5,000 times. Even worse, the nested for loop (foreach ($usedProducts as $associatedProduct)) is going to cause this to run even more than than the already unnecessary 5,000 times. While both issues are addressing the same function and the same issue, they are addressing them in different ways (and the test case used to test issue #90 might have been completely inaccurate depending on the number of super attributes that it was tested against). |
…ETWO-54785-State-province-not-required-mainline [Fearless kiwis] MAGETWO-54785: [GitHub] State/Province field doesn't show as required on the add new address page. #5279
This was a problem in 1.x Magento as well.
$productAttribute->getFrontend()->getSelectOptions(); basically grabs all available options, regardless if they are relevant to the product. Not a big issue if you have a small set of super attributes but if you have an amount numbering in the thousands or more, it can cause additional time on on any for loops that are using the returning data.
All credit to turnkeye (http://turnkeye.com/blog/magento-perfomance-optimization-of-configurable-products)
Implementing these changes saves us around 300ms per product in an add to cart call (we have around 2,000 super attributes) or any cart save call.
Mage_Catalog_Model_Resource_Product_Type_Configurable_Attribute_Collection
protected function _loadPrices() (line 266)
Replace:
$options = $productAttribute->getFrontend()->getSelectOptions();
With:
$_options = array();
foreach ($_prods as $associatedProduct) {
$_options[] = $associatedProduct->getData($productAttribute->getAttributeCode());
}
$options = $productAttribute->getSource()->getNeededOptions($_options)
Mage_Eav_Model_Entity_Attribute_Source_Table
Add function:
public function getNeededOptions($ids) {
$storeId = $this->getAttribute()->getStoreId();
$collection = Mage::getResourceModel('eav/entity_attribute_option_collection')
->setPositionOrder('asc')
->setAttributeFilter($this->getAttribute()->getId())
->addFieldToFilter('main_table.option_id', array('in' => $ids))
->setStoreFilter($this->getAttribute()->getStoreId())
->load();
return $collection->toOptionArray();
}
This logic can also be applied to $value->getSource()->getOptionText($attributeValue); which also calls $this->getAllOptions(false) and loads all of the options unnecessarily.
The text was updated successfully, but these errors were encountered: