Jump to content

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


Recommended 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,

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

  • 4 weeks later...

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;



...

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

  • 2 weeks later...

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.

Link to comment
Share on other sites

×
×
  • Create New...