[해결] 제품 페이지에서 PHP 변수로 제품 ID 및 URL 가져 오기
-
12-12-2019 - |
문제
제품 페이지에서 제품 URL을 읽으려고합니다 ("nofollow"> http : //www.example.com / myCategory / myProduct.html )을 PHP 변수에 PHP 변수에 넣으십시오.나는 또한 제품의 ID로 이것을 원한다.
해결책
다음과 같이 현재 페이지의 현재 URL을 가져올 수 있습니다.
$url = Mage::helper('core/url')->getCurrentUrl();
.
다음과 같이 제품 페이지에서 제품 ID를 얻을 수 있습니다.
$product = Mage::registry('current_product');
if ($product) {
$id = $product->getId();
}
else {
//it means you are not in a product page
$id = null;
}
. 다른 팁
not get Product url from this url
를 사용할 수 있습니다
제품 ID를 얻으려면 Registry variable which give u product id
를 사용하십시오.
if (Mage::registry('current_product')) {
$Productid = Mage::registry('current_product')->getId();
}
.
은 제품 페이지 에있을 때만 작동합니다.
제휴하지 않습니다 magento.stackexchange