久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

magento 中的 Ajax(加載產(chǎn)品視圖塊)

Ajax in magento (load product view block)(magento 中的 Ajax(加載產(chǎn)品視圖塊))
本文介紹了magento 中的 Ajax(加載產(chǎn)品視圖塊)的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!

問題描述

我想要達到的目標:點擊產(chǎn)品鏈接/圖片(至少在某些區(qū)域)以打開包含完整產(chǎn)品信息(基本上是產(chǎn)品查看頁面的所有內(nèi)容)的彈出窗口.

What I want to achieve: Clicking on a product link/image (at least in certain areas) to open a pop-up with the full product information (basically all the contents of the product view page).

到目前為止我所做/嘗試的:

What I did/tried so far:

  • 創(chuàng)建了 ajax php 代碼之外的所有內(nèi)容(模塊、鏈接、模板、重寫)
  • 創(chuàng)建了 ajax 控制器(可以通過類似于以下的鏈接訪問:http://test.com/index.php/ajaxproductview/ajax/index/id/2).
  • 遵循各種教程(如this 或 this ) - 幫助我走到這一步.但我不想加載我的自定義塊,我想要默認的產(chǎn)品視圖塊.
  • 嘗試在 indexAction() 中添加一些代碼.它到達那里,但代碼失敗.我沒有收到任何錯誤/通知/報告,只是看起來像是殺死我的處理器的無限循環(huán).

  • created all the stuff outside the ajax php code (the module, links, templates, rewrites)
  • created the ajax controller (which can be accessed with a link similar to: http://test.com/index.php/ajaxproductview/ajax/index/id/2 ).
  • to follow various tutorials ( like this or this ) - that helped me get this far. But I don't want to load my custom block, I want the default product view block(s).
  • tried to add some code in the indexAction(). It gets there, but the code fails. I don't get any errors/notices/reports, just what it seems like an infinite loop that kills my processor.

$body = $this
    ->getLayout()
    ->createBlock('product.info') // taken from catalog.xml
    ->toHtml();
$this->getResponse()->setBody($body);

所有其他頁面都運行良好,它是一個全新的 magento,僅安裝并激活了magneto 和我的模塊.

All the other pages work fine, and it's a fresh magento with only magneto and my module installed and activated.

我的 AJAX 函數(shù)只是獲取這個 HTML 響應(yīng),將它放入一個 div,然后打開一個彈出窗口.

My AJAX function simply gets this HTML response, puts it into a div, and opens a pop-up.

我的問題是(是) - 如何設(shè)置產(chǎn)品 ID,以便塊知道要加載的產(chǎn)品,以及如何正確加載此塊.我也嘗試過類似的東西:

My question(s) is(are) - how can I set the product id, so the block knows what product to load, and how can I load this block correctly. I also tried something similar to this:

謝謝.

PS:我也試過這個:

    $layout = $this->getLayout();
    $update = $layout->getUpdate();
    $update->load('catalog_product_view');
    $layout->generateXml();
    $layout->generateBlocks();
    $output = $layout->getOutput(); // $output is an empty string

推薦答案

Product 控制器使用幫助器來設(shè)置活動產(chǎn)品.你應(yīng)該可以在你的控制器中做同樣的事情!

The Product controller uses a helper to set the active product. You should be able to do the same in your controller!

在進行布局之前試試這個:

Try this before you do your layouting:

$productId  = (int) $this->getRequest()->getParam('id');
Mage::helper('catalog/product')->initProduct($productId, $this);

還有一點需要注意:如果你添加一個像 product.info 塊這樣的塊.如果它在其模板文件中調(diào)用它們,則需要額外的子塊.

Another thing to be aware of: If you add a block like the product.info block. It needs additional child blocks if it calls them in its template file.

使用自定義布局 xml 文件最簡單.然后,您可以為您的操作句柄添加特定布局(您的操作句柄由 <frontend><routers> 下的模塊 etc/config.xml 文件中的路由器節(jié)點組成,例如 <Yourmodule> 節(jié)點,確保將其小寫!然后用下劃線添加控制器名稱和操作名稱,在您的情況下為 index_index),如下所示:

It would be easiest to use a custom layout xml file. You can then add a specific layout for your action handle (your action handle consists of your routers node in your module's etc/config.xml file under <frontend><routers>, e.g. <Yourmodule> node, make sure to lowercase it! And then with underscores add the controller name and action name, in your case index_index) like this:

<yourmodule_index_index>
    <remove name="right"/>
    <remove name="left"/>
    <block type="catalog/product_view" name="root" output="toHtml" template="catalog/product/view.phtml">
    <!-- Add all the child blocks you need -->
    </block>
</yourmodule_index_index>

這使 view.phtml 成為使用其 toHtml 方法呈現(xiàn)自身的根塊.因此,在您的控制器操作中,您只需要上面的兩行代碼,然后:

This makes the view.phtml the root block which renders itself using its toHtml method. Therefore, in your controller action, all you need is my two lines above and then:

$this->loadLayout();
$this->renderLayout();

這篇關(guān)于magento 中的 Ajax(加載產(chǎn)品視圖塊)的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網(wǎng)!

【網(wǎng)站聲明】本站部分內(nèi)容來源于互聯(lián)網(wǎng),旨在幫助大家更快的解決問題,如果有圖片或者內(nèi)容侵犯了您的權(quán)益,請聯(lián)系我們刪除處理,感謝您的支持!

相關(guān)文檔推薦

Joining 2 tables in SELECT(MYSQL/PHP)(在 SELECT(MYSQL/PHP) 中加入 2 個表)
How to make lt;option selected=quot;selectedquot;gt; set by MySQL and PHP?(如何使lt;option selected=“selectedgt;由 MySQL 和 PHP 設(shè)置?)
Auto populate a select box using an array in PHP(使用 PHP 中的數(shù)組自動填充選擇框)
PHP SQL SELECT where like search item with multiple words(PHP SQL SELECT where like search item with multiple words)
json_encode produce JSON_ERROR_UTF8 from MSSQL-SELECT(json_encode 從 MSSQL-SELECT 產(chǎn)生 JSON_ERROR_UTF8)
MySQL ORDER BY rand(), name ASC(MySQL ORDER BY rand(),名稱 ASC)
主站蜘蛛池模板: a级片在线观看 | 中文字幕乱码一区二区三区 | 久久久久亚洲精品国产 | 精品视频一区二区在线观看 | 黄色av网站在线免费观看 | 欧洲一区二区在线 | 欧美亚洲国产成人 | 国产成人99久久亚洲综合精品 | 成人免费网站www网站高清 | 日韩中文字幕在线视频 | 国产精品乱码一区二三区小蝌蚪 | 日韩综合一区 | 91在线精品一区二区 | 久久久精品综合 | 国产激情视频网址 | 99国产精品久久久久老师 | 日韩精品一区二区三区中文在线 | 亚洲欧美另类在线 | 黄色大片免费网站 | 午夜影院在线视频 | 成人久久久 | 精品国产伦一区二区三区观看说明 | 精久久 | jizz视频 | 久久久www成人免费精品 | 在线视频一区二区三区 | 国产不卡一区 | 日韩精品一区在线观看 | 在线一级片 | 亚洲午夜av久久乱码 | 日本一区二区在线视频 | 日韩中文字幕一区二区 | 欧美午夜精品理论片a级按摩 | 国产欧美日韩综合精品一区二区 | 亚洲一区二区视频在线播放 | 成人在线免费电影 | 久久久久免费精品国产 | a国产一区二区免费入口 | 秋霞在线一区 | 中文字幕动漫成人 | 国产日韩免费观看 |