j2store use thumbimage and mainimage instead of joomla article intro and full image for show image product at j2store cart and order invoice

enter image description here

I decided to use intro image in article instead of j2store thumbnail image for show at j2store cart and invoice

enter image description here

enter image description here

this code for j2store cart and checkout that load thumb image product

    $registry = new JRegistry;
    $item->params = $registry;
    $thumb_image = $item->params->get('thumb_image', '');
    $back_order_text = $item->params->get('back_order_item', '');

and this code for show image at cart

<?php if($this->params->get('show_thumb_cart', 1) && !empty($thumb_image)): ?>
    <span class="cart-thumb-image">
    <a href="<?php echo $item->cartitem->product_view_url;?>">
        <img alt="<?php echo $item->orderitem_name; ?>" src="<?php echo $thumb_image; ?>" >
<?php endif; ?>

now I want use joomla article intro image show at cart How to render and show joomla intro image at cart ?

1 Answer 1


Cart view doesn't load Joomla images so you have to retrieve them. This can be done in the layout override or with a plugin. There are several plugin events that could be used. I'm using onJ2StoreBeforeDisplayCart because it passes all items at once. This allows to run a single query for all products in cart.

defined('_JEXEC') or die;

use Joomla\CMS\Plugin\CMSPlugin;

class plgJ2StoreCartimage extends CMSPlugin
    protected $db;

    public function onJ2StoreBeforeDisplayCart($items)
        // Get article IDs.
        $ids = array_column($items, 'product_source_id');

        // Get article images from the database.
        $query = $this->db->getQuery(true)
            ->select($this->db->quoteName(array('id', 'images')))
            ->where($this->db->quoteName('id') . ' IN (' . implode(',', $ids) . ')');

        // Index on ID for easy access.
        $data = $this->db->setQuery($query)->loadObjectList('id');

        foreach ($items as $item)
            $images = json_decode($data[$item->product_source_id]->images);
            $item->thumb_image = $images->image_intro;

I'm not familiar with J2Store but I noticed product object contains $product_source property which defines which extension the product belongs to (e.g. com_content). Assuming that it's possible to store products in multiple extensions, you might want to check the extension before getting the IDs and running the query:

$ids = [];

foreach ($items as $item)
    if ($item->product_source === 'com_content')
        $ids[] = $item->product_source_id;
  • thank you ..It is possible to explain more ? Where do I put the codes?
    – user9530
    Feb 13, 2019 at 9:35
  • You would put this in a new PHP file. Also create a manifest XML file. Then zip them together and install through Extension Manager. You can install this plugin in j2store group so in manifest file's <extension> tag use group="j2store". See Creating a Plugin for Joomla documentation for details.
    – Sharky
    Feb 13, 2019 at 9:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.