Get eCommerce attribute value by handle
Permalink 4 users found helpful
What is the best way to get an ecommerce product attribute value by handle?
In case anyone is wondering, here was the solution:
I get this error, even though the product attribute exists and the handle is correct:
Fatal error: Call to a member function getAttributeValueObject() on a non-object
Fatal error: Call to a member function getAttributeValueObject() on a non-object
....yes, because the 3rd line:
is incorrect - or, doesn't show the variable "$product" as being an instance of the CoreCommerceProductAttributeKey class (which might have happened early in jgarcia's code). So (your) PHP doesn't know where to look for the getAttributeValueObject method. Solve that problem and you'll be good to go.
$myAttributeValueObject = $product->getAttributeValueObject($myAttribute);
is incorrect - or, doesn't show the variable "$product" as being an instance of the CoreCommerceProductAttributeKey class (which might have happened early in jgarcia's code). So (your) PHP doesn't know where to look for the getAttributeValueObject method. Solve that problem and you'll be good to go.
@Ricasin,
I'm stuck with the same problem, how do you solve that please ?
Thank you very much
I'm stuck with the same problem, how do you solve that please ?
Thank you very much
I was able to achieve setting $product like this within a block controller on_page_view():
$page = Page::getCurrentPage();
$pageid = $page->getCollectionID();
$db = Loader::db();
Loader::model('product/model', 'core_commerce');
$uh = Loader::helper('urls', 'core_commerce');
$productid = $db->GetOne('select productID from CoreCommerceProducts where cID = ?', array($pageid));
if ($productid > 0) {
$product = CoreCommerceProduct::getByID($productid);
}
$page = Page::getCurrentPage();
$pageid = $page->getCollectionID();
$db = Loader::db();
Loader::model('product/model', 'core_commerce');
$uh = Loader::helper('urls', 'core_commerce');
$productid = $db->GetOne('select productID from CoreCommerceProducts where cID = ?', array($pageid));
if ($productid > 0) {
$product = CoreCommerceProduct::getByID($productid);
}
Thanks for this sollution! I was really struggling on this :)
Thank you! This answer helped me get a regular CollectionAttribute value. I didn't know about CollectionAttributeValueObject.