0

Given a collection obtained by (this is Magento 1.4):

$collection = Mage::getModel('catalog/product_option')
    ->getProductOptionCollection($_product);

This returns the collection of options associated with a single product. I would like to filter this down to only give me options that have a price_type of percent, so naturally, I try:

$collection = Mage::getModel('catalog/product_option')
    ->getProductOptionCollection($_product)
    ->addFieldToFilter('price_type', array('eq' => 'percent'));

This still returns the entire option collection, as if the filter did nothing at all. Is this an old issue with v.1.4?

2
  • Did you try changing price_type to default_option_price.price_type? Oct 9, 2014 at 20:54
  • Indeed I have. For now, I have resorted to a couple foreach loops that gets the values from each option and just pushes those with ['price_type'] == 'percent' to a new array. This is an old site that will be gone soon and I'm not able to spend much time on it and I fear that some of the rewritten models (including options, products, values, etc) are what is giving me fits.
    – pspahn
    Oct 9, 2014 at 21:20

1 Answer 1

1

Testing the query product by your code in version 1.7.* i got the following error in MySql Workbench "Error Code: 1052. Column 'price_type' in where clause is ambiguous"

Try

 $_product = Mage::getModel('catalog/product')->load(1);
 $collection = Mage::getModel('catalog/product_option')
               ->getProductOptionCollection($_product)
               ->addFieldToFilter('default_option_price.price_type', array('eq' => 'percent'));

Try debugging using

echo $collection->getSelect();

See

v1.7

/app/code/core/Mage/Catalog/Model/Resource/Product/Option/Collection.php

v1.4

/app/code/core/Mage/Catalog/Model/Resource/Eav/Mysql4/Product/Option/Collection.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.