Accessing productID for when viewing a product's web page
Permalink
Hi,
When viewing a product's web page, is there any way to access the associated productID?
I am developing functionality that occurs when viewing a product.
I need to access the associated productID for the currently viewed web page.
I managed to get it working very dodgily by searching a productlist for the current web page name- but as the product title has since changed, and the associated page name has not..obviously this is now broken and was never going to be a proper solution...
When viewing a product's web page, is there any way to access the associated productID?
I am developing functionality that occurs when viewing a product.
I need to access the associated productID for the currently viewed web page.
I managed to get it working very dodgily by searching a productlist for the current web page name- but as the product title has since changed, and the associated page name has not..obviously this is now broken and was never going to be a proper solution...
$page = Page::getCurrentPage(); $pageName = $page->vObj->cvName; $pl = new CoreCommerceProductList();//'filterBy', $pl->filterByKeywords($pageName); $matches = $pl->get(); foreach($matches as $match){ $productName = strtolower(str_replace('-',' ',$match->prName)); $pageName = strtolower($pageName); if($productName==$pageName){ $productID = $match->productID; } }