0
votes

I'm trying to write some code that bridges Magento with Drupal and I want a simple way of adding Magento's frontend JavaScript to pages served by Drupal.

To this end: how do I return an array of URLs to JavaScript files used by Magento on the frontend? Specifically, I'm looking for the default layout handle and the individual product page.

Thanks!

1
That will very much depend on the page. You can't just load 'the Magento frontend JS files', since the JS files are added to the page based on layout handles and will differ depending on the layout handles on the page. - Peter O'Callaghan
@Cags That makes sense. I've updated the question accordingly. - aendra

1 Answers

3
votes

This will get you pretty close:

$update = Mage::app()->getLayout()->getUpdate();
$update->load(array('default','catalog_product_view'));
$xml = $update->asSimplexml();
$js = $xml->xpath('//action[@method="addJs"]');
Zend_Debug::dump($js);

The xpath argument could be refined to //action[@method="addJs"]/script for core code.

Of course, there are other arguments which add JS files (e.g. addItem) which will require additional handling.