I'm trying to add J2Store item price to the (my modified) built-in joomla mod_articles_latest.

I'm able to get a 'complete' Add to Cart block with this code :

$product = F0FTable::getAnInstance('Product', 'J2StoreTable')->getClone();
            if($product->get_product_by_source('com_content', $item->id)) {
            echo $product->get_product_html();

But how can I get any of elements on that block partially? For example, how can I get the price only or add to cart button only?

  • This task a little more complicated than that, since if you have a product item (a Joomla article) then it can be also a variable product or flexible product in J2Store, thus an item can have more prices and can have more variant_ids with corresponding prices. From the table you try to use you will not be able to get these. From the J2Store table ‘variants’, maybe. And the correct J2Store model should be used/invoked for having these. Just for a hint on this question
    – Zollie
    Commented May 15, 2019 at 7:29
  • In my case, the product type is always "Simple" one, so I'm just want to get the base_price
    – webchun
    Commented May 15, 2019 at 7:48
  • Yes, I see. Even if you do not have variants, it looks like that J2Store gives a variant_id for all of the products and in j2store_product_prices table, that given id is connected to the product price (not the product_id). If I see that correctly.
    – Zollie
    Commented May 15, 2019 at 7:56
  • I see. Ok, thanks @Zollie
    – webchun
    Commented May 15, 2019 at 8:07

1 Answer 1


There are methods for this:

// Show price.
echo $product->get_product_price_html();

// Show cart button.
echo $product->get_product_cart_html();
  • Thanks. I did that get_product_price_html() before but it returned nothing and I get error message : Warning : Parameter 1 to plgContentJ2Store::onJ2StoreAfterGetProduct() expected to be a reference, value given in /.../libraries/joomla/event/event.php on line 70
    – webchun
    Commented May 15, 2019 at 6:57
  • @webchun - as far as I know, this warning is coming from a core bug in j2Store basically, so even if it is there you could use the above. It is not appearing in production environment if you turn off error messages on your live site. This warning is coming from the fact that j2store developers wanted to leave their codes backward compatible with PHP5.6, and as I remember they made a note on this on their forum board many months ago. They probably still not repaired that part of their code. Probably they are more busy with Joomla 4 upgrade prepare now.
    – Zollie
    Commented May 15, 2019 at 11:23
  • However I do not know why this method (@Sharky pointed to) does not return back the expected values.
    – Zollie
    Commented May 15, 2019 at 11:26

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.