在结帐后的成功页面(success.phtml)上,我想仅在购买了某个产品 ID 时才运行脚本。这可能吗?
我正在使用 Magento 1.4.2。
尝试将此添加到 Success.phtml
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getItemsCollection();
$sku = $ids = array();
foreach($items as $item){
//$sku[] = $item->getSku();
$p_ids[] = $item->getProductId();
}
$p_id = 16;
if(in_array($p_id, $p_ids)){
//run script
}
这种逻辑可能适用于 success.phtml 页面。
$
if($this->getOrderId()) {
$found = false;
$skuToFind = 'abc';
$order = Mage::getModel('sales/order')->loadByIncrementId($this->getOrderId());
$items = $order->getAllItems();
foreach ($items as $i => $item) {
if($item->getSku() == $skuToFind) {
$found = true; break;
}
}
if($found) { echo "Product Found"; } else { echo "No Found"; }
?>
好吧,您只需要找到购物车变量。我不确定确切的变量,但回显 $_SESSION 会告诉你它们在哪里。查看以下示例代码:
if(in_array('2324242', $_SESSION['product_ids'])
{//in this case 2324242 is the product ID you are looking for
//Require_once ('script');
//Or redirect to script.php
}