I am currently developing a product configurator. I am submitting a form which sends the admin option values of my custom attributes via POST to a controller action. If I use the current store's attribute option labels all is working just fine, the product collection is filtered correctly and a simple product which is associated to a configurable product is returned. Sadly I am using the admin values for form and URL generation because the default swedish store values contain too many special characters.
So my question is: how do I get the right product from my collection when using the admin option values or more specific, how do I get the admin option value's ID like using this for the default store's values:
$id = Mage::getResourceModel('catalog/product')
->getAttribute($key)
->getSource()
->getOptionId($value);
I already tried filtering by addStoreFilter(0), but that didn't work either. I already read that it could have something to do with flat tables being used in default store but not for admin, but I am rather unexperienced with Magento, so I don't really understand the difference using flat tables and what that really means.
Here is my last question concerning the filtering for reference: addFieldToFilter doesn't return the right product for selected attribute values
Here is my getProduct() function:
public function getProduct($attributes)
{
Mage::Log($attributes);
$productModel = Mage::getModel('catalog/product');
//Get Product Collection
$collection = $productModel->getCollection()
//Filter for Selected Product
$collection->addAttributeToSelect('status');
$collection->addAttributeToSelect('doorconfig_enable');
$collection->addAttributeToFilter('doorconfig_enable',array('eq' => 1));
foreach ($attributes as $key => $value)
{
$collection->addAttributeToSelect($key);
$id = Mage::getResourceModel('catalog/product')
->getAttribute($key)
->getSource()
->getOptionId($value);
$collection->addAttributeToFilter($key,
array(
'eq' => $id
)
);
}
$selection = $collection->getSelect()->__toString();
Mage::Log($selection);
Mage::log($collection->getSize(),null,'custom.log');
$product = $collection->getFirstItem();
return $product;
}