[solved]get Product ID and URL from Product page as PHP variable
-
12-12-2019 - |
Question
On the product page, I want to read the Product URL (http://www.example.com/myCategory/myProduct.html) and put it as string in a PHP variable like $myProductURL
. I also want do to this with the ID of the product.
Solution
You can get the current url of any page like this:
$url = Mage::helper('core/url')->getCurrentUrl();
and you can get the product id in a product page like this:
$product = Mage::registry('current_product');
if ($product) {
$id = $product->getId();
}
else {
//it means you are not in a product page
$id = null;
}
OTHER TIPS
You can not get Product url from this url
if you want to get product id then use Registry variable which give u product id
if (Mage::registry('current_product')) {
$Productid = Mage::registry('current_product')->getId();
}
But note that it is only working when you are in product page
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange