Author Topic: [SOLVED] Get product_id/product object from module in product page  (Read 520 times)

EvanGR

  • Jr. Member
  • **
  • Posts: 484
Hello,

Simple question.
I am developing a custom module that goes in the Product page.
I need to retrieve the current product id (and product data object, which should be easy once I find the id)

I use SEF urls so I can't pick it up from there.

Any ideas?

Thanks

Jumbo!

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 828
  • Full-stack Web Developer
    • www.virtueplanet.com
  • VirtueMart Version: Always latest
Re: Get product_id/product object from module in product page
« Reply #1 on: June 02, 2022, 14:18:41 pm »
Code: [Select]
<?php
JLoader
::register('VmConfig'JPATH_ADMINISTRATOR '/components/com_virtuemart/helpers/config.php');

VmConfig::loadConfig();

$productId                JFactory::getApplication()->input->getInt('virtuemart_product_id'0);
$productModel             VmModel::getModel('product');
$ratingModel              VmModel::getModel('ratings');
$productModel->withRating $ratingModel->showRating($productId);
$product                  $productModel->getProduct($productIdtruetruetrue1); // Get the product object.

$productModel->addImages($product);
?>

pinochico

  • 3rd party VirtueMart Developer
  • Full Member
  • *
  • Posts: 1522
    • MiniJoomla
  • Skype Name: support-easysoftware
  • VirtueMart Version: 3
Re: Get product_id/product object from module in product page
« Reply #2 on: June 02, 2022, 14:18:55 pm »
Try this - From our VM related product extended module + slideshow (https://www.minijoomla.org/extensions/virtuemart-extensions/related-products-extended-for-virtuemart):

Code: [Select]
if($current_view == "productdetails") {
$product_id = JRequest::getInt('virtuemart_product_id',0);
$productModel = VmModel::getModel('Product');
$front = true;
$onlyPublished = true;
$single = true;
$products = $productModel->getProducts($product_id, $front, $show_price, $onlyPublished, $single);
$productModel->addImages($products);
}

www.minijoomla.org  - new portal for Joomla!, Virtuemart and other extensions
XML Easy Feeder - feeds for FB, GMC,.. from products, categories, orders, users, articles, acymailing subscribers and database table
Virtuemart Email Manager - customs email templates
Import products for Virtuemart - from CSV and XML
Rich Snippets - Google Structured Data
VirtueMart Products Extended - Slider with products, show Others bought, Products by CF ID and others filtering products

EvanGR

  • Jr. Member
  • **
  • Posts: 484
Re: Get product_id/product object from module in product page
« Reply #3 on: June 03, 2022, 08:52:39 am »
Thank you!