## Patch to Hide "item in stock" for downloadable products. Sean Boran http://boran.com/presta ## See http://www.prestashop.com/forums/newreply/10649/ ## Delete these four lines before using the patch. ## The patch was created with svn diff classes/Product.php; svn diff product.php; svn diff classes/Cart.php;svn diff themes/default/product.tpl; svn diff product-sort.php; Index: classes/Product.php =================================================================== --- classes/Product.php (revision 463) +++ classes/Product.php (working copy) @@ -14,6 +14,8 @@ define('_CUSTOMIZE_FILE_', 0); define('_CUSTOMIZE_TEXTFIELD_', 1); +/* SB: leave FirePHP code for bedugging if needed */ +require_once(dirname(__FILE__) .'/../FirePHPCore/FirePHP.class.php'); class Product extends ObjectModel { @@ -1340,6 +1342,11 @@ if (!is_array($product)) die (Tools::displayError()); + /* SB: if the product is downloadable, don't update quantity + http://www.prestashop.com/forums/newreply/10649/ */ + if ( Product::getProductIsDownloadable($product['id_product']) ); + return true; + $result = Db::getInstance()->getRow(' SELECT `quantity` FROM `'._DB_PREFIX_.($product['id_product_attribute'] ? 'product_attribute' : 'product').'` @@ -1798,9 +1805,27 @@ $row['id_image'] = Product::defineProductImage($row); $row['features'] = Product::getFrontFeaturesStatic(intval($id_lang), $row['id_product']); $row['allow_oosp'] = Product::isAvailableWhenOutOfStock($row['out_of_stock']); + # Setting is_downloadable does not work here, it must be in /product.php around line 102 + #$row['is_downloadable'] = Product::getProductIsDownloadable($row['id_product']); /* SB */ return $row; } + /* SB: Is this product downloadable? e.g. Used for stock management decisions */ + static public function getProductIsDownloadable($id_product) + { + $fb = FirePHP::getInstance(true); + + $sql= ' SELECT COUNT(`id_product_download`) AS total FROM `' ._DB_PREFIX_.'product_download' + .'` WHERE `id_product` = '.intval($id_product); + #$fb->log($sql, 'getProductIsDownloadable()'); + $row = Db::getInstance()->getRow($sql); + #$fb->log('id ' .$id_product .'>' .$row['total'], 'getProductIsDownloadable()'); + if (intval($row['total'])>0) + return true; + else + return false; + } + static public function getProductsProperties($id_lang, $query_result) { $resultsArray = array(); Index: product.php =================================================================== --- product.php (revision 463) +++ product.php (working copy) @@ -99,6 +99,7 @@ else { $smarty->assign('virtual', ProductDownload::getIdFromIdProduct(intval($product->id))); + $smarty->assign('is_downloadable', Product::getProductIsDownloadable(intval($product->id))); // SB /* Product pictures management */ require_once('images.inc.php'); Index: classes/Cart.php =================================================================== --- classes/Cart.php (revision 463) +++ classes/Cart.php (working copy) @@ -12,6 +12,8 @@ * */ +require_once(dirname(__FILE__) .'/../FirePHPCore/FirePHP.class.php'); // SB: debugging only + class Cart extends ObjectModel { public $id; @@ -889,6 +891,15 @@ { if (Configuration::get('PS_STOCK_MANAGEMENT')) foreach ($this->getProducts() AS $product) + + /* SB: if the product is downloadable, don't update quantity + http://www.prestashop.com/forums/newreply/10649/ */ + #$fb = FirePHP::getInstance(true); + #$fb->log('''', 'checkQuantities()'); + if ( Product::getProductIsDownloadable($product['id_product']) ); + return true; + + if (!$product['active'] OR (!$product['allow_oosp'] AND $product['stock_quantity'] < $product['quantity'])) { Tools::dieObject($product); Index: themes/default/product.tpl =================================================================== --- themes/default/product.tpl (revision 463) +++ themes/default/product.tpl (working copy) @@ -219,19 +219,24 @@

- + +

quantity == 0 && !$product->available_later) || (!$product->available_now && $display_qties != 1) } style="display:none;"{/if}> + {if !$is_downloadable} {l s='Availability:'} quantity == 0} class="warning-inline"{/if}> {if $product->quantity == 0}{if $allow_oosp}{$product->available_later}{else}{l s='This product is no longer in stock'}{/if}{else}{$product->available_now}{/if} + {/if}

quantity == 0)} style="display:none;"{/if}> + {if !$is_downloadable} {$product->quantity|intval} quantity > 1} style="display:none;"{/if} id="quantityAvailableTxt">{l s='item in stock'} quantity < 2} style="display:none;"{/if} id="quantityAvailableTxtMultiple">{l s='items in stock'} + {/if}

Index: product-sort.php =================================================================== --- product-sort.php (revision 463) +++ product-sort.php (working copy) @@ -1,6 +1,12 @@ 'name', 1 => 'price', 2 => 'date_add', 3 => 'date_upd', 4 => 'position', 5 => 'manufacturer_name', 6 => 'quantity'); $orderWayValues = array(0 => 'ASC', 1 => 'DESC'); $orderBy = Tools::strtolower(Tools::getValue('orderby', $orderByValues[intval(Configuration::get('PS_PRODUCTS_ORDER_BY'))]));