在我的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