在结帐后的成功页面(success.phtml)上,我想只在购买了某个产品ID时才运行脚本。这可能吗?
我正在使用Magento 1.4.2。
答案 0 :(得分: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
}
答案 1 :(得分:1)
这种逻辑可能适用于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"; }
>
答案 2 :(得分:0)
嗯,你只需要找到购物车变量。我不确定确切的变量,但回应$ _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
}