monsieurbiz/mbiz_ajax

Magento module which adds some ajax features.

Installs: 34

Dependents: 1

Suggesters: 0

Security: 0

Stars: 1

Watchers: 3

Forks: 0

Open Issues: 0

Type:magento-module

0.1.0 2016-07-22 19:42 UTC

This package is auto-updated.

Last update: 2024-03-29 03:31:57 UTC


README

This modules adds AJAX_ handles if the request is performed using ajax call.

It also adds a simple JSON response of the category view.

You have to write your own ajax if you want to make it works.

Javascript example:

(function ($) {
  $(document).ready(function () {
    // Catalog Category View
    if ($('.catalog-category-view').length) {

      // If we have a load more button
      var $more = $('.js-load-more');
      if ($more.length) {

        // On click on this button
        $more.click(function () {

          // Call the next page url in ajax
          var pagerData = {};
          pagerData[$more.attr('data-page-var-name')] = $more.attr('data-next-page');
          $.getJSON(
            {
              url: $more.attr('data-url'),
              dataType: 'json',
              data: pagerData,
              success: function (data) {

                // Disable if last page
                if (data.is_last_page) {
                  $more
                    .attr('disabled', true)
                    .addClass('disabled')
                  ;
                }

                // Insert products
                $('.product-list').append(data.body);

                // Update next page
                $more.attr('data-next-page', data.next_page);
              }
            }
          );

        });
      }
    }
  });
})(jQuery);

You can also use the handles to perform some updates on the page in ajax mode.

Example:

<AJAX_catalog_category_view>
    <reference name="product_list">
        <!-- Change template of the product list -->
        <action method="setTemplate">
            <template>catalog/product/list_ajax.phtml</template>
        </action>
    </reference>
</AJAX_catalog_category_view>