WT JShopping Cart

WT JShopping Cart

Downloads 18494 Hits 13844 CTR 134% Mod Free

Shopping cart module for Joomla 4, Joomla 5 and JoomShopping 5. Made on Bootstrap 5.

WT JShopping Cart

Description

The cart module for JoomShopping 5 has eight layouts.

  • default - standard output of the JoomShopping bucket. Not related to Bootstrap at all.
  • bootstrap5-icon - displays the cart module as a link-button with the basket icon and the quantity of goods in the form of a badge. It is convenient to place such a module in the header of the site or the mobile version of the site in the lower or upper panels.
  • bootstrap5-icon-and-text is a link-button similar to bootstrap5-icon, but with the word "basket" and the amount of goods in the basket.
  • bootstrap5-list-group - the bucket module is output as of the Bootstrap 5 List group component. It can be placed in the right or left columns of the site. In this layout, you can display the attributes of the goods, the weight of the goods.
  • bootstrap5-offcanvas -the bucket module is output as Bootstrap 5 Offcanvas component - floating to the right or panel on the left. This is essentially a bootstrap5-list-group layout wrapped in an Offcanvas component.In this layout, you can display the attributes of the goods, the weight of the goods.
  • bootstrap5-icon-btn - this layout is a copy of the bootstrap5-icon layout with the following changes: the module is output not by a link (tag ), but by a button (tag <button>). Learn more about goals and settings below.
  • uikit-offcanvas displays a cart panel for UIkit templates, including YOOtheme.
  • uikit-icon-btn displays a button with the item count that opens the uikit-offcanvas panel.

Video

Configuring the module using Bootstrap 5 Offcanvas

You want to display the basket as a panel floating out from the edge of the screen. According to Bootstrap 5.2 documentation to open or hide this panel, you need a toggler button (switch). It can be either a link (tag <a>) or a button (tag <button>).You can create such a button yourself in an HTML code type module and place it in the right place, or create a menu item with the necessary attributes. 

However, if you would like to show the number of products near the basket icon and at the same time use it to open the basket module in Offcanvas - use the layoutbootstrap5-icon-btn.

You create 2 modules with different layouts: one with the layout bootstrap5-offcanvas (you need to remember its ID), the second with the layout bootstrap5-icon-btn. In the settings of the second module, you need to specify the parameter"ID of the module with the offcanvas layout", so that when you click on the button with the basket, the first offcanvas module appears.This parameter is used to set the data-bs-target attribute of the button.

A module with the bootstrap5-offcanvas layout is recommended to be published in the debug position or similar so that the content of the module has the body tag as the parent element. This is due to the peculiarities of the CSS property z-index.

Setting up the UIkit cart panel

Publish two instances of the module with the uikit-offcanvas and uikit-icon-btn layouts. In the button module settings, select the panel module in the offcanvas target field. Assign both modules to the same pages. The site template supplies UIkit, as it does in YOOtheme.

Setting up links to the cart and checkout

In order for the links to the shopping cart and JoomShopping checkout in the module to be "beautiful", you should create menu items of both types. Usually they are made hidden - this is in the settings of the menu item.

AJAX add to cart

Install WT JShopping Cart 1.2.0 and enable the WT JShopping AJAX Add to Cart plugin in the jshoppingproducts group. The Ajax-cart tab in the plugin settings has selectors for the product list and product detail page. The examples below use the default selectors [wt-jshopping-add-to-cart-btn] for buttons and [wt-jshopping-add-to-cart-qty] for quantity fields.

Replace <template> in the paths below with the active JoomShopping template name. The bundled template is named default.

Product list

Add the assignment to the opening PHP block of components/com_jshopping/templates/<template>/category/products.php before it includes the list. For pages rendered with components/com_jshopping/templates/<template>/products/products.php, add the same assignment at the top of that file.

$wtAjaxCartEnabled = \Joomla\CMS\Plugin\PluginHelper::isEnabled(
    'jshoppingproducts',
    'wtjshoppingproductsajaxaddtocart'
);

In components/com_jshopping/templates/<template>/list_products/product.php, replace the existing purchase control for each product with the block below. The $product variable is already available in this layout. When the plugin is disabled, the original purchase link is displayed.

<?php
$ajaxAvailable = ($wtAjaxCartEnabled ?? false) && isset($product->wtAjaxCartInCart);
$inCart = $ajaxAvailable && !empty($product->wtAjaxCartInCart);
$buttonText = $inCart
    ? $product->wtAjaxCartButtonText . ' ' . $product->wtAjaxCartQuantity
    : \Joomla\CMS\Language\Text::_('JSHOP_BUY');
$buttonClass = $inCart ? ' ' . $product->wtAjaxCartButtonClass : '';
?>
<?php if ($product->buy_link) : ?>
    <?php if ($ajaxAvailable) : ?>
        <button type="button"
            class="btn btn-primary<?php echo htmlspecialchars($buttonClass, ENT_QUOTES, 'UTF-8'); ?>"
            wt-jshopping-add-to-cart-btn
            data-wt-jshopping-add-to-cart-text="<?php echo htmlspecialchars(\Joomla\CMS\Language\Text::_('JSHOP_BUY'), ENT_QUOTES, 'UTF-8'); ?>"
            data-product-id="<?php echo (int) $product->product_id; ?>"
            data-product-category-id="<?php echo (int) ($product->category_id ?? 0); ?>">
            <span wt-jshopping-add-to-cart-label><?php echo htmlspecialchars($buttonText, ENT_QUOTES, 'UTF-8'); ?></span>
        </button>
    <?php else : ?>
        <a class="btn btn-primary button_buy"
            href="/<?php echo htmlspecialchars($product->buy_link, ENT_QUOTES, 'UTF-8', false); ?>">
            <?php echo \Joomla\CMS\Language\Text::_('JSHOP_BUY'); ?>
        </a>
    <?php endif; ?>
<?php endif; ?>

If a list item already has a quantity field, add the wt-jshopping-add-to-cart-qty attribute or set its CSS selector in the plugin. If the item has no quantity field, the example button adds one unit.

Product detail page

In components/com_jshopping/templates/<template>/product/product_default.php, replace the quantity field and purchase button inside the existing product form with this block. Keep the form action, hidden fields, attribute inputs and wishlist button. JoomShopping uses id="quantity" to update the price.

<?php
$wtAjaxCartEnabled = \Joomla\CMS\Plugin\PluginHelper::isEnabled(
    'jshoppingproducts',
    'wtjshoppingproductsajaxaddtocart'
);
$product = $this->product;
$ajaxAvailable = $wtAjaxCartEnabled && isset($product->wtAjaxCartInCart);
$inCart = $ajaxAvailable && !empty($product->wtAjaxCartInCart);
$buttonText = $inCart
    ? $product->wtAjaxCartButtonText . ' ' . $product->wtAjaxCartQuantity
    : \Joomla\CMS\Language\Text::_('JSHOP_ADD_TO_CART');
$buttonClass = $inCart ? ' ' . $product->wtAjaxCartButtonClass : '';
?>
<input type="<?php echo htmlspecialchars($this->prod_qty_input_type, ENT_QUOTES, 'UTF-8'); ?>"
    name="quantity" id="quantity" min="0"
    value="<?php echo htmlspecialchars((string) $this->default_count_product, ENT_QUOTES, 'UTF-8'); ?>"
    aria-label="<?php echo htmlspecialchars(\Joomla\CMS\Language\Text::_('JSHOP_QUANTITY'), ENT_QUOTES, 'UTF-8'); ?>"
    oninput="jshop.reloadPrices();"<?php echo $ajaxAvailable ? ' wt-jshopping-add-to-cart-qty' : ''; ?>>
<?php echo $this->_tmp_qty_unit; ?>
<button type="submit"
    class="btn btn-primary btn-buy<?php echo htmlspecialchars($buttonClass, ENT_QUOTES, 'UTF-8'); ?>"
    data-wt-jshopping-add-to-cart-text="<?php echo htmlspecialchars(\Joomla\CMS\Language\Text::_('JSHOP_ADD_TO_CART'), ENT_QUOTES, 'UTF-8'); ?>"
    onclick="this.form.elements.to.value = 'cart';"<?php echo $ajaxAvailable ? ' wt-jshopping-add-to-cart-btn' : ''; ?>>
    <span<?php echo $ajaxAvailable ? ' wt-jshopping-add-to-cart-label' : ''; ?>><?php echo htmlspecialchars($buttonText, ENT_QUOTES, 'UTF-8'); ?></span>
</button>

To use AJAX buttons for related products, move the $wtAjaxCartEnabled assignment from this example to the opening PHP block of product/product_default.php. The product/related.php layout then passes the flag to the included list_products/product.php.

Joomla

Extension type:
Module
Location:
Site
Joomla version:
4.0, 4.1, 4.2, 4.3.3, , 5.1.0, 5.2.1, 6.2.0

What's new

Addition

AJAX add to cart

The package installs the cart module and the AJAX add-to-cart plugin for JoomShopping 5. Enable the plugin after installation. Its Ajax-cart tab lets you set CSS selectors and includes PHP examples for the product list and product detail templates.
Addition

UIkit offcanvas cart

Added uikit-offcanvas and uikit-icon-btn layouts for UIkit templates, including YOOtheme. Both the Bootstrap 5 and UIkit panels update their product lists without reloading the page.
Fixed

Cart totals and product links

The module shows JoomShopping’s discounted total after a cart change and preserves decimal quantities and prices. Product links stay in the current language after an AJAX update.

WebTolk Joomla Extensions

114 Extensions
12 Categories
591 Versions released
964410 Downloads