From 3e2d0086fa90bd1325070d23b2f1fb2b1d43c8f4 Mon Sep 17 00:00:00 2001 From: lBrieu Date: Mon, 3 Oct 2011 13:05:08 +0000 Subject: [PATCH] [*] FO : Update filename if product has combinations (and files associated to them) --- classes/Order.php | 16 +++++++++++++--- classes/ProductDownload.php | 17 +++++++++++++++++ 2 files changed, 30 insertions(+), 3 deletions(-) diff --git a/classes/Order.php b/classes/Order.php index 3b8198394..ed09b7ad2 100644 --- a/classes/Order.php +++ b/classes/Order.php @@ -495,12 +495,22 @@ class OrderCore extends ObjectModel $this->setProductPrices($row); /* Add information for virtual product */ - if ($row['download_hash'] AND !empty($row['download_hash'])) - $row['filename'] = ProductDownload::getFilenameFromIdProduct($row['product_id']); - + if ($row['download_hash'] && !empty($row['download_hash'])) + { + if ($row['product_attribute_id'] && !empty($row['product_attribute_id'])) + { + $row['filename'] = ProductDownload::getFilenameFromIdAttribute((int)$row['product_id'], (int)$row['product_attribute_id']); + } + else + { + $row['filename'] = ProductDownload::getFilenameFromIdProduct((int)$row['product_id']); + } + } /* Stock product */ $resultArray[(int)$row['id_order_detail']] = $row; } + p($resultArray); + return $resultArray; } diff --git a/classes/ProductDownload.php b/classes/ProductDownload.php index 0fdecb81f..7ef24e8e5 100644 --- a/classes/ProductDownload.php +++ b/classes/ProductDownload.php @@ -269,6 +269,23 @@ class ProductDownloadCore extends ObjectModel WHERE `id_product` = '.(int)$id_product.' AND `active` = 1'); } + + /** + * Return the filename from an id_product_attribute + * + * @param int $id_product Product the id + * @param int $id_product_attribute Attribute the id + * @return string Filename the filename for this virtual product + */ + public static function getFilenameFromIdAttribute($id_product, $id_product_attribute) + { + return Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue(' + SELECT `filename` + FROM `'._DB_PREFIX_.'product_download` + WHERE `id_product` = '.(int)$id_product.' + AND `id_product_attribute` = '.(int)$id_product_attribute.' + AND `active` = 1'); + } /** * Return the display filename from a physical filename