PrestaShop Forum

The best place in the world to ask questions about PrestaShop and get advice from our passionate community!

PrestaShop Forum

Jump to content

 

[resolved] Hide "item in stock" for downloadable products

11 replies to this topic
#1
boran

    PrestaShop Apprentice

  • Members
  • PipPip
  • 42 posts
Hi,

When a buyer selects a downloadable product, it tries to manage the stock with messages like:

1 item in stock
Warning: Last items in stock!

Is there a way to disable stock management for these products, since its not relevant.

Thanks in avance,

#2
jhnstcks

    PrestaShop Fanatic

  • Moderators
  • 1913 posts
Theres an option in the BO>preferences>products to disable/enable stock management.
Helpful hints and tips to Empower your Prestashop site - Join us on Facebook and get involved, tell us the things that help you.
If you think someone's answer helped, please give him/her a Positive Reputation vote by liking their post.
E-commerce hosting from Scotserve, fast, reliable and affordable.

#3
boran

    PrestaShop Apprentice

  • Members
  • PipPip
  • 42 posts
Yes, thanks. Thats for all products though.
The idea would be to disable stock management for downloadable products.

#4
TropischBruin

    PrestaShop Fanatic

  • Moderators
  • 2198 posts
This would mean that you should create a difference in the query when a check on the stock is done for "virtual" and "real" products.
This is something that needs to be coded in you PS files.
Norman in 't VeldtModeratorPrestaShopForums
Help PrestaShop, make a donation!

#5
boran

    PrestaShop Apprentice

  • Members
  • PipPip
  • 42 posts
As a start I changed in themes/prestashop/product.tpl

<!-- number of item in stock -->

quantity == 0)} style="display:none;"{/if}>


to

downloadable)) && ($display_qties != 1 || ($allow_oosp && $product->quantity == 0) )} style="display:none;"{/if}>


but that didn't seem to make any difference.

I'm new to PS code changes, suggestions on where to start?

#6
TropischBruin

    PrestaShop Fanatic

  • Moderators
  • 2198 posts
I think that you should first identify and separate the virtual products from the real products before you can build a stock-filter.
Norman in 't VeldtModeratorPrestaShopForums
Help PrestaShop, make a donation!

#7
boran

    PrestaShop Apprentice

  • Members
  • PipPip
  • 42 posts
I have a category for them, and in the product settings there is a a tickbox "Is this a downloadable product?" which is mapped to a label is_virtual_good. I'm not sure how to reference this flag from $product in themes/prestashop/product.tpl though.

There is a not a downloadable flag in the products, its a separate table.
Perhaps someone could provide links or tips on accessing the product objects from .tpl files?

#8
jaumeortola

    PrestaShop Newbie

  • Members
  • Pip
  • 2 posts
In my shop I have downloadables and non-downloadables products. I need to stop managing stocks for downloadable products. I have added these lines in Product.php, and it works.


public static function updateQuantity($product)
{
if (!is_array($product))
die (Tools::displayError());

/* if the product is downloadable, don't update quantity */
$result = Db::getInstance()->getRow('
SELECT *
FROM `'._DB_PREFIX_.'product_download'.'`
WHERE `id_product` = '.intval($product['id_product']));
if ($result)
return true;


...

#9
boran

    PrestaShop Apprentice

  • Members
  • PipPip
  • 42 posts
Thanks, so this will stop the stock from being decremented when a sale is made?

The SQL might be more efficient if one just did "SELECT id_product_download" as opposed to "SELECT *"?
Or perhaps, use getIdFromIdProduct() from ProductDownload.php?

Maybe your code is also needed in checkQuantities() in Cart.php?
And product-sort.php?
As these are all places where PS_STOCK_MANAGEMENT is referenced.

But what about getting rid of "Availability: 1000 items in stock" on the item details page?
I think that needs to be handled on the display level, thus themes/prestashop/product.tpl?

There is a $display_qties in themes/prestashop/product.tpl, but I don't understand how it is set, can you help?

#10
boran

    PrestaShop Apprentice

  • Members
  • PipPip
  • 42 posts
Hmm. So I created a method in Product.php

        static public function getProductIsDownloadable($id_product)
{
$result = Db::getInstance()->getRow(' SELECT id_product_download FROM `'._DB_PREFIX_.'product_download'.'`
WHERE `id_product` = '.intval($id_product));
if ($result)
return true;
else
return false;
}



Then added to getProductProperties():
                $row['is_downloadable'] = Product::getProductIsDownloadable($row['id_product']);   /* SB */


And in "themes/product.tpl" reference is_downloadable:

                        

quantity == 0 && !$product->available_later) || (!$product->available_now && $display_qties != 1) } style="display:none;"{/if}>
{l s='Availability:'}



"Availability:" is still shown on the stock page, so there must be a bug in my logic above, in how to get the downloadable flag onto the smarty template and control the display based on that.

#11
boran

    PrestaShop Apprentice

  • Members
  • PipPip
  • 42 posts
Ok, the issues is resolved, a patch that does the job has been attached to this post.

Changes are needed to classes/Product.php product.php classes/Cart.php themes/default/product.tpl

I'll put it up on boran.com/presta where I keep my notes.

#12
boran

    PrestaShop Apprentice

  • Members
  • PipPip
  • 42 posts
I'm trying to attach a patch to this post, but it is not showing up.
Is there some trick to get attachments to work correctly?

I've posted it here:
http://boran.com/sit...rum_10649_0.txt