在我的Magento商店中,我添加了可下载的产品,如果用户想下载此产品,用户需要订阅我们的通讯。为此,我在view.phtml file.code中添加了通讯录订阅块。获取可下载的产品样本链接通讯SubscriberController Magento
<?php $download = Mage::registry('current_product')->getTypeId();?>
<?php
if($download == 'downloadable')
{ ?>
<div class="pop-upss">
<input type="button" onclick="showMrnlePopup();" value="To Download This Product You Need To Subscribe Our Newsletter" name="submit"/>
</div>
<?php } ?>
所以我设置了onclick函数,当用户点击这个按钮时,通讯弹出窗口会打开。
在通讯PHTML文件我得到当前产品的ID使用下面的代码
<input type="hidden" name="pro_id" value="<?php echo Mage::registry('current_product')->getId();?>">
好了,现在我们去SubscriberController.php文件和它的newAction()。我使用下面的代码在newAction()中获取当前产品ID。
$product_id = $this->getRequest()->getPost('pro_id');
现在我想用这个产品ID:
1)。我需要关于当前产品的所有数据。 - >我得到这是使用下面的代码:
if($product_id) {
$obj = Mage::getModel('catalog/product');
$_product = $obj->load($product_id);
echo '<pre>';
print_r($_product->getData());
die;
}
2)。如果这个产品是可下载的,那么我希望它是样本数据,它是下载产品的链接,但我无法获得当前产品的下载链接。我的代码获取下载链接如下。
if($_product->hasSamples()) {
$_samples = $this->getSamples();
foreach ($_samples as $_sample){
echo $samplePath = $_sample->getBasePath();
echo $sampleFile = $_sample->getSampleFile();
}
} else {
echo 'not getting anything here...';
}
当我运行上面的代码时,它会进入其他部分并回显'没有得到任何东西......'。 所以请任何人知道我如何获得可下载的产品链接请帮助我。
谢谢。
你能告诉我从你的控制器完整的'newAction()'方法吗? – codedge