From e40ee879dcfa23cd96ff1da6f5a9d75fa918f863 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Tue, 23 Oct 2018 13:07:09 +0200 Subject: [PATCH] New: works with variants: - If product is variant disable prices modify - Add function isVariant for knowing if product is a Variant --- htdocs/langs/en_US/products.lang | 1 + htdocs/product/class/product.class.php | 30 ++++++++++++++++ htdocs/product/price.php | 47 ++++++++++++++------------ 3 files changed, 56 insertions(+), 22 deletions(-) diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 8390eb5439d..95b93aba4e9 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -331,6 +331,7 @@ NbProducts=No. of products ParentProduct=Parent product HideChildProducts=Hide variant products ShowChildProducts=Show variant products +NoEditVariants=Go to Parent product card and edit variants price impact in the variants tab ConfirmCloneProductCombinations=Would you like to copy all the product variants to the other parent product with the given reference? CloneDestinationReference=Destination product reference ErrorCopyProductCombinations=There was an error while copying the product variants diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 2d2e7b75ed2..f8326a60721 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3529,6 +3529,36 @@ class Product extends CommonObject return $nb; } + + /** + * Return if loaded product is a variant + * + * @return int + */ + function isVariant() + { + global $conf; + if (!empty($conf->variants->enabled)) { + $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "product_attribute_combination WHERE fk_product_child = " . $this->id . " AND entity IN (" . getEntity('product') . ")"; + + $query = $this->db->query($sql); + + if ($query) { + if (!$this->db->num_rows($query)) { + return false; + } + return true; + } else { + dol_print_error($this->db); + return -1; + } + + } else { + return false; + } + + } + /** * Return all parent products for current product (first level only) * diff --git a/htdocs/product/price.php b/htdocs/product/price.php index a72ea28928b..9fb67aaa86c 100644 --- a/htdocs/product/price.php +++ b/htdocs/product/price.php @@ -5,7 +5,7 @@ * Copyright (C) 2005-2017 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2014 Florian Henry - * Copyright (C) 2014-2016 Juanjo Menent + * Copyright (C) 2014-2018 Juanjo Menent * Copyright (C) 2014-2018 Philippe Grand * Copyright (C) 2014 Ion agorria * Copyright (C) 2015 Alexandre Spangaro @@ -1109,30 +1109,33 @@ if (! $action || $action == 'delete' || $action == 'showlog_customer_price' || $ { print "\n" . '
' . "\n"; - if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) - { - if ($user->rights->produit->creer || $user->rights->service->creer) { - print ''; - } - } + if ($object->isVariant()) { + if ($user->rights->produit->creer || $user->rights->service->creer) { + print ''; + } + } else { + if (empty($conf->global->PRODUIT_MULTIPRICES) && empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { + if ($user->rights->produit->creer || $user->rights->service->creer) { + print ''; + } + } - if (! empty($conf->global->PRODUIT_CUSTOMER_PRICES)) - { - if ($user->rights->produit->creer || $user->rights->service->creer) { - print ''; - } - } + if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) { + if ($user->rights->produit->creer || $user->rights->service->creer) { + print ''; + } + } - if (! empty($conf->global->PRODUIT_MULTIPRICES) || ! empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) - { - if ($user->rights->produit->creer || $user->rights->service->creer) { - print ''; - } + if (!empty($conf->global->PRODUIT_MULTIPRICES) || !empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES)) { + if ($user->rights->produit->creer || $user->rights->service->creer) { + print ''; + } - if ($user->rights->produit->creer || $user->rights->service->creer) { - print ''; - } - } + if ($user->rights->produit->creer || $user->rights->service->creer) { + print ''; + } + } + } print "\n
\n"; }