[解決済]製品ページから製品IDとURLをPHP変数として取得する
-
12-12-2019 - |
質問
製品ページでは、製品のURL(href="http://www.example.com//www.example.com//wwator/myproduct.html" rel="nofollow"> http://www.example)を読みたいです。.com / mycategory / myproduct.html )と$myProductURL
のような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