VirtueMart Forum

VirtueMart 2 + 3 + 4 => General Questions => Topic started by: sprachrohr on March 01, 2017, 14:48:41 PM

Title: Module to show one specific Product
Post by: sprachrohr on March 01, 2017, 14:48:41 PM
Hi,

does anyone know a module to show only one specific product?

Thanks!
Best regards!

Edit by Mod: yes, here http://extensions.virtuemart.net/product/products/product-presenter-detail
Title: Re: Module to show one specific Product
Post by: jenkinhill on March 01, 2017, 15:21:49 PM
I use a special category when this is required. Make a new category - eg "Manager's Special"  and assign your single product to that category (products can be assigned to more than one category).

Then using the standard VirtueMart Products module, set that module to display a single random product, set the category filter to Yes and select that special category. Publish the module wherever you like.

Then if the featured product is to change, just remove the category from the current product and assigne to the new one.  This is simple enough for most store owners to be able to manage!
Title: Re: Module to show one specific Product
Post by: sprachrohr on March 01, 2017, 15:38:40 PM
Thanks for your answer!

Yes, this workaround should work. But my customer wants to show a lot of products that way. So he has to deal with many additional categories.

It would be very nice to select the product in the module.

Maybe someone else knows a module?
Title: Re: Module to show one specific Product
Post by: jenkinhill on March 01, 2017, 15:55:25 PM
There was a ,module for VM2 - http://forum.virtuemart.net/index.php?topic=99676.0  but I don't think there was much demand.

With my way you can choose to display several products in the module if you wish as long as they are all assigned to that category. Just configuration.   But it should not be too difficult to code a module to display a singe product based on product_id
Title: Re: Module to show one specific Product
Post by: sprachrohr on March 01, 2017, 16:04:30 PM
Thanks again,

yes you are right... if noone knows a module, i'll code it by myselfe.

When i follow your link, the page of the developer is dead.
But thanks for your help!

Title: Re: Module to show one specific Product
Post by: Studio 42 on March 01, 2017, 18:45:59 PM
Quote from: sprachrohr on March 01, 2017, 16:04:30 PM
Thanks again,

yes you are right... if noone knows a module, i'll code it by myselfe.

When i follow your link, the page of the developer is dead.
But thanks for your help!


CHeck mod_virtuemart_products you have the main code to do it.
You need an ID option to select the product
ANd replace
$products = $productModel->getProductListing($Product_group, $max_items, $show_price, true, false,$filter_category, $category_id);
with
$product = $productModel->getProduct ($id); or getProducts($ids), if you need multiple products
See https://shop.st42.fr/en/products/virtuemart-selected-product-s.htm i added it for free in my shop.
Title: Re: Module to show one specific Product *CLOSED*
Post by: sprachrohr on March 02, 2017, 16:57:26 PM
thanks a lot!

I've coded it by myselfe.
best regards!
Title: Re: Module to show one specific Product
Post by: cihancomcom on May 31, 2017, 10:35:52 AM
I am trying to do the same. Please let me know how to code it.
Title: Re: Module to show one specific Product
Post by: sprachrohr on May 31, 2017, 10:46:11 AM
Quote from: cihancomcom on May 31, 2017, 10:35:52 AM
I am trying to do the same. Please let me know how to code it.

Hi,

what exactly do you want to know?

Did you read the post from studio 42? That is all you need.
Title: Re: Module to show one specific Product
Post by: cihancomcom on May 31, 2017, 10:52:00 AM
I changed the code

$products = $productModel->getProductListing($Product_group, $max_items, $show_price, true, false,$filter_category, $category_id);
with
$product = $productModel->getProduct ($id);

It did not work?

Please let me know What I am doing wrong.

Thanks a lot.
Title: Re: Module to show one specific Product
Post by: sprachrohr on May 31, 2017, 11:21:10 AM
so first off all, you should not add these lines of code to mod_virtuemart_product. You should create a new/own module. In my case i created "mod_virtuemart_single_product".
If you add these lines of code and modify the core module, you will lose your changes in case of an virtuemart update.

Do you know how to do that? If not, maybe you shoud read some documentation first: https://docs.joomla.org/Portal:Developers/en#Modules

You also have to modify the xml-file to get an id option in your module configuration. In my case, this looks like this (you have to adust it to your needs!!!):

<field
   name="productId"
   type="sql"
   default="1"
   label="MOD_VIRTUEMART_SINGLE_PRODUCT_SELECT_A_PRODUCT"
   query="SELECT virtuemart_product_id, product_name FROM #__virtuemart_products_de_de"
   key_field="virtuemart_product_id"
       value_field="product_name"
   required="true"
      header="MOD_VIRTUEMART_SINGLE_PRODUCT_PLEASE_SELECT_A_PRODUCT"
/>

Now i have a dropdown to select the product. You could also use other form fileds like text maybe.

You can access it by:
$product_id = $params->get( 'productId', '1');

And then use it like this:
$product = $productModel->getProduct ($product_id);

Hope this helps. Im sorry that i cannot give you access to my module because of customers restrictions.
Title: Re: Module to show one specific Product
Post by: spammg on June 17, 2017, 21:10:16 PM
Your advice is very good and I had already implemented it, however I've got one question. How one can recall product photo to $product_id?
Title: Re: Module to show one specific Product
Post by: aftertaf on June 22, 2017, 20:22:35 PM
Anyone want to share their module? ;)
looking for same features but newbie PHP and I don't have the time to check it out...

Sent from my ASUS_Z017D using Tapatalk

Title: Re: Module to show one specific Product
Post by: Studio 42 on August 19, 2017, 03:03:03 AM
I shared in my shop a module that i wrote for a customer.
Note that this have minimum options.
Can be downloaded here https://shop.st42.fr/en/products/virtuemart-selected-product-s.htm
You only have to fill product ID's separated by commas