Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Obviously you cannot do exactly that as PHP is run on the server and the Modalbox is run in JavaScript in the client's browser - potentially on opposite sides of the world, as much as we like to forget physical barriers do have an effect on software. The best we can do is insert Javascript code in appropriate places so that the browser eventually executes it.</p> <p>The first concrete sign of an item being added is the <code>checkout_cart_product_add_after</code> event. Create a module and amend it's <code>config.xml</code> file;</p> <pre><code>&lt;config&gt; &lt;!-- ...usual blocks, helpers and models stuff here... --&gt; &lt;frontend&gt; &lt;!-- this is the safest way to catch items being added --&gt; &lt;events&gt; &lt;checkout_cart_product_add_after&gt; &lt;observers&gt; &lt;yourmodule_product_add&gt; &lt;class&gt;yourmodule/observer&lt;/class&gt; &lt;method&gt;onProductAdd&lt;/method&gt; &lt;/yourmodule_product_add&gt; &lt;/observers&gt; &lt;/checkout_cart_product_add_after&gt; &lt;/events&gt; &lt;!-- will need to insert a block later --&gt; &lt;layout&gt; &lt;updates&gt; &lt;yourmodule&gt; &lt;file&gt;yourmodule.xml&lt;/file&gt; &lt;/yourmodule&gt; &lt;/updates&gt; &lt;/layout&gt; &lt;/frontend&gt; &lt;/config&gt; </code></pre> <p>That declares an observer which it expects to find in <code>Your/Module/Model/Observer.php</code>;</p> <pre><code>class Your_Module_Model_Observer { public function onProductAdd() { // page might redirect immediately so make a flag for now Mage::getSingleton('checkout/session')-&gt;setShowModalbox(true); } } </code></pre> <p>You should be able to see what will happen next. A file was earlier declared as <code>app/design/frontend/base/default/layout/yourmodule.xml</code>;</p> <pre><code>&lt;layout&gt; &lt;!-- hook this block for all pages because anything might be shown after adding a product --&gt; &lt;default&gt; &lt;reference name="before_body_end"&gt; &lt;block type="yourmodule/modalbox" name="yourmodule_modalbox" /&gt; &lt;/reference&gt; &lt;/default&gt; &lt;default&gt; &lt;/layout&gt; </code></pre> <p>The final step is to make <code>Your/Module/Block/Modalbox.php</code> which will actually insert the relevant Javascript when necessary;</p> <pre><code>class Your_Module_Block_Modalbox extends Mage_Core_Block_Text_Tag_Js { protected function _toHtml() { if (!Mage::getSingleton('checkout/session')-&gt;getShowModalbox()) return $this; $url = 'URL to show in Modalbox'; $this-&gt;setContents("Modalbox.show({$url}, {width: 600});"); Mage::getSingleton('checkout/session')-&gt;unsShowModalBox(); return parent::_toHtml(); } } </code></pre> <hr> <p><sub>This is the only best practice way I can think of but I am enamoured with <code>Mage_Core_Block_Text_Tag_Js</code> having just discovered it. As the saying goes 'when all you have is a hammer all problems start to look like nails'. I may be missing something simpler and more obvious.</sub></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload