2015-02-09 82 views
1

正如标题所示,我试图显示“注销此产品的库存时会收到通知”链接旁边的“出的股票“标签。Magento 1.9 - echo“缺货”标签旁边的产品库存警示

因此,它应该是这样的:
Example

我经历的所有的模板,并在template/catalog/product/view.phtml有这样的代码片段:
<?php echo $this->getChildHtml('alert_urls') ?>,这是由:
template/productalert/product/view.phtml(其中只包含。代码呼应实际的链接)我想什么在这个模板做的是类似于下面的东西,在那里我有INSERT STOCK ALERT LINK HERE

<?php $_product = $this->getProduct() ?> 

<?php if ($this->displayProductStockStatus()): ?> 
    <?php if ($_product->isAvailable()): ?> 
     <p class="availability in-stock"> 
      <span><?php echo $this->__('In stock') ?></span> 
     </p> 
    <?php else: ?> 
     <p class="availability out-of-stock"> 
      <span><?php echo $this->__('Out of stock') ?></span> 
      <!-- ******* INSERT STOCK ALERT LINK HERE ******* --> 
     </p> 
    <?php endif; ?> 
<?php endif; ?> 
<?php echo $this->getChildHtml('product_type_data_extra') ?> 
<?php echo $this->getPriceHtml($_product) ?> 

我有残疾镨冰警报,因为这是不需要的。所以唯一的警报就是注册股票通知。

我试过很多东西,但我想也许它是$this变量的范围,它阻止我访问它。您的建议或建议是最受欢迎的!

回答

1

好了,我只是碰到这种页面传来:http://forum.azmagento.com/how-to/product-alert-notify-html-in-product-list-view-55751.html,这给如何编辑在核心文件中的getSaveURL()功能指令(亚克西!)/app/code/core/Mage/ProductAlert/Helper/Data.php用下面的代码:

public function getSaveUrl($type, $product = null) 
{ 
    if (!empty($product)) 
    { 
     $product_id = $product->getId(); 
    } 
    else 
    { 
     $product_id = $this->getProduct()->getId(); 
    } 

    return $this->_getUrl('productalert/add/' . $type, array(
     'product_id' => $product_id, 
     Mage_Core_Controller_Front_Action::PARAM_NAME_URL_ENCODED => $this->getEncodedUrl() 
    )); 
} 

和然后在phtml中输出链接:<a href="<?php echo Mage::helper('productalert')->getSaveUrl('stock', $_product); ?>">&nbsp;Notify Me When Available</a>

现在这个效果很好,但我有点犹豫是否需要修改一个涉及修改Core文件的解决方案。有什么办法可以在不覆盖任何核心文件的情况下使用上面的代码片段?