From 925a1475a126672daf934a9da06079c911f9621e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Fri, 4 Sep 2020 11:01:47 +0200
Subject: [PATCH 01/18] add ref_ext to ProductCombination.class.php
---
.../class/ProductCombination.class.php | 105 ++++++++++++------
1 file changed, 72 insertions(+), 33 deletions(-)
diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php
index 4c25e32c9da..a4faa6121a0 100644
--- a/htdocs/variants/class/ProductCombination.class.php
+++ b/htdocs/variants/class/ProductCombination.class.php
@@ -76,6 +76,12 @@ class ProductCombination
* @var ProductCombinationLevel[]
*/
public $combination_price_levels;
+
+ /**
+ * External ref
+ * @var string
+ */
+ public $variation_ref_ext = '';
/**
* Constructor
@@ -100,7 +106,7 @@ class ProductCombination
{
global $conf;
- $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE rowid = ".(int) $rowid." AND entity IN (".getEntity('product').")";
+ $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, variation_ref_ext FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE rowid = ".(int) $rowid." AND entity IN (".getEntity('product').")";
$query = $this->db->query($sql);
@@ -120,6 +126,7 @@ class ProductCombination
$this->variation_price = $obj->variation_price;
$this->variation_price_percentage = $obj->variation_price_percentage;
$this->variation_weight = $obj->variation_weight;
+ $this->variation_ref_ext = $obj->variation_ref_ext;
if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
$this->fetchCombinationPriceLevels();
@@ -226,44 +233,72 @@ class ProductCombination
}
}
+ /**
+ * Get fk_product_parent by fk_product_child
+ *
+ * @param int $fk_child Product row id
+ * @return int >0 OK <0 KO
+ */
+ public function getFkProductParentByFkProductChild($fk_child)
+ {
+ $sql = "SELECT fk_product_parent FROM ".MAIN_DB_PREFIX."product_attribute_combination";
+ $sql .= " WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').") LIMIT 1";
- /**
- * Retrieves a product combination by a child product row id
- *
- * @param int $fk_child Product row id
- * @return int <0 KO, >0 OK
- */
- public function fetchByFkProductChild($fk_child)
- {
- global $conf;
+ $query = $this->db->query($sql);
- $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').")";
+ if (!$query) {
+ return -1;
+ }
- $query = $this->db->query($sql);
+ if (!$this->db->num_rows($query)) {
+ return -1;
+ }
- if (!$query) {
- return -1;
- }
+ $row = $this->db->fetch_object($query);
- if (!$this->db->num_rows($query)) {
- return -1;
- }
+ return (int) $row->fk_product_parent;
+ }
- $result = $this->db->fetch_object($query);
- $this->id = $result->rowid;
- $this->fk_product_parent = $result->fk_product_parent;
- $this->fk_product_child = $result->fk_product_child;
- $this->variation_price = $result->variation_price;
- $this->variation_price_percentage = $result->variation_price_percentage;
- $this->variation_weight = $result->variation_weight;
+ /**
+ * Retrieves all product combinations by the child product row id
+ *
+ * @param int $fk_child Product row id
+ * @return int|ProductCombination[] <0 KO
+ */
+ public function fetchAllByFkProductChild($fk_child)
+ {
+ global $conf;
- if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
- $this->fetchCombinationPriceLevels();
- }
+ $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, variation_ref_ext FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').")";
- return 1;
- }
+ $query = $this->db->query($sql);
+
+ if (!$query) {
+ return -1;
+ }
+
+ $return = array();
+
+ while ($result = $this->db->fetch_object($query)) {
+ $tmp = new ProductCombination($this->db);
+ $tmp->id = $result->rowid;
+ $tmp->fk_product_parent = $result->fk_product_parent;
+ $tmp->fk_product_child = $result->fk_product_child;
+ $tmp->variation_price = $result->variation_price;
+ $tmp->variation_price_percentage = $result->variation_price_percentage;
+ $tmp->variation_weight = $result->variation_weight;
+ $tmp->variation_ref_ext = $result->variation_ref_ext;
+
+ if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
+ $tmp->fetchCombinationPriceLevels();
+ }
+
+ $return[] = $tmp;
+ }
+
+ return $return;
+ }
/**
* Retrieves all product combinations by the product parent row id
@@ -293,6 +328,7 @@ class ProductCombination
$tmp->variation_price = $result->variation_price;
$tmp->variation_price_percentage = $result->variation_price_percentage;
$tmp->variation_weight = $result->variation_weight;
+ $tmp->variation_ref_ext = $result->variation_ref_ext;
if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
$tmp->fetchCombinationPriceLevels();
@@ -340,7 +376,7 @@ class ProductCombination
$sql .= " (fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, entity)";
$sql .= " VALUES (".((int) $this->fk_product_parent).", ".((int) $this->fk_product_child).",";
$sql .= (float) $this->variation_price.", ".(int) $this->variation_price_percentage.",";
- $sql .= (float) $this->variation_weight.", ".(int) $this->entity.")";
+ $sql .= (float) $this->variation_weight.", '".$this->db->escape($this->variation_ref_ext)."', ".(int) $this->entity.")";
$resql = $this->db->query($sql);
if ($resql) {
@@ -373,7 +409,8 @@ class ProductCombination
$sql = "UPDATE ".MAIN_DB_PREFIX."product_attribute_combination";
$sql .= " SET fk_product_parent = ".(int) $this->fk_product_parent.", fk_product_child = ".(int) $this->fk_product_child.",";
$sql .= " variation_price = ".(float) $this->variation_price.", variation_price_percentage = ".(int) $this->variation_price_percentage.",";
- $sql .= " variation_weight = ".(float) $this->variation_weight." WHERE rowid = ".((int) $this->id);
+ $sql .= " variation_ref_ext = '".$this->db->escape($this->variation_ref_ext)."',";
+ $sql .= " variation_weight = ".(float) $this->variation_weight." WHERE rowid = ".((int) $this->id);
$resql = $this->db->query($sql);
if (! $resql) {
@@ -661,9 +698,10 @@ class ProductCombination
* @param bool|float $forced_pricevar If the price variation is forced
* @param bool|float $forced_weightvar If the weight variation is forced
* @param bool|string $forced_refvar If the reference is forced
+ * @param string $ref_ext External reference
* @return int <0 KO, >0 OK
*/
- public function createProductCombination(User $user, Product $product, array $combinations, array $variations, $price_var_percent = false, $forced_pricevar = false, $forced_weightvar = false, $forced_refvar = false)
+ public function createProductCombination(User $user, Product $product, array $combinations, array $variations, $price_var_percent = false, $forced_pricevar = false, $forced_weightvar = false, $forced_refvar = false, $ref_ext = '')
{
global $db, $conf;
@@ -779,6 +817,7 @@ class ProductCombination
$newcomb->variation_price_percentage = $price_var_percent;
$newcomb->variation_price = $price_impact[1];
$newcomb->variation_weight = $weight_impact;
+ $newcomb->variation_ref_ext = $db->escape($ref_ext);
// Init price level
if ($conf->global->PRODUIT_MULTIPRICES){
From 0f1c3643d7db798fa9e38984ea596b68b84cf878 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Fri, 4 Sep 2020 11:21:29 +0200
Subject: [PATCH 02/18] Use function getFkProductParentByFkProductChild
---
htdocs/core/lib/product.lib.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php
index dfc57313add..686ff3af1f5 100644
--- a/htdocs/core/lib/product.lib.php
+++ b/htdocs/core/lib/product.lib.php
@@ -107,7 +107,7 @@ function product_prepare_head($object)
$prodcomb = new ProductCombination($db);
- if ($prodcomb->fetchByFkProductChild($object->id) == -1)
+ if ($prodcomb->getFkProductParentByFkProductChild($object->id) == -1)
{
$head[$h][0] = DOL_URL_ROOT."/variants/combinations.php?id=".$object->id;
$head[$h][1] = $langs->trans('ProductCombinations');
From 3d926ff3a180b19c176dcdcfeced966891005374 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Fri, 4 Sep 2020 11:38:40 +0200
Subject: [PATCH 03/18] use function getFkProductParentByFkProductChild
---
htdocs/product/card.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 32c50ccb661..bfb630f4eb9 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -1912,9 +1912,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
if (!empty($conf->variants->enabled) && ($object->isProduct() || $object->isService())) {
$combination = new ProductCombination($db);
- if ($combination->fetchByFkProductChild($object->id) > 0) {
+ if (($fk_product_parent = $combination->getFkProductParentByFkProductChild($object->id)) > 0) {
$prodstatic = new Product($db);
- $prodstatic->fetch($combination->fk_product_parent);
+ $prodstatic->fetch($fk_product_parent);
// Parent product
print '
| '.$langs->trans("ParentProduct").' | ';
From 3a232796d8878d35e71b6f9d0f8412254a260363 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Fri, 4 Sep 2020 11:43:56 +0200
Subject: [PATCH 04/18] Use new function fetchAllByFkProductChild
---
htdocs/product/class/product.class.php | 10 +++++++---
1 file changed, 7 insertions(+), 3 deletions(-)
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index 1fcb76a571d..7d91052ab87 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -1194,9 +1194,13 @@ class Product extends CommonObject
}
//We also check if it is a child product
- if (!$error && ($prodcomb->fetchByFkProductChild($this->id) > 0) && ($prodcomb->delete($user) < 0)) {
- $error++;
- $this->errors[] = 'Error deleting child combination';
+ if (!$error) {
+ foreach ($prodcomb->fetchAllByFkProductChild($this->id) as $obj) {
+ if ($obj->delete($user) < 0) {
+ $error++;
+ $this->errors[] = 'Error deleting child combination';
+ }
+ }
}
}
From 93959d34c8f4020529bf98c4442a4afc658281e2 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Fri, 4 Sep 2020 12:01:01 +0200
Subject: [PATCH 05/18] NEW fields ref_ext for Attributes and Combinations
---
htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql
index 17b58f278cf..35f2e4e8a54 100644
--- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql
+++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql
@@ -310,4 +310,8 @@ ALTER TABLE llx_actioncomm_reminder ADD INDEX idx_actioncomm_reminder_status (st
ALTER TABLE llx_inventorydet ADD UNIQUE uk_inventorydet(fk_inventory, fk_warehouse, fk_product, batch);
+ALTER TABLE llx_product_attribute ADD COLUMN ref_ext varchar(255) AFTER ref;
+ALTER TABLE llx_product_attribute_combination ADD COLUMN variation_ref_ext varchar(255) AFTER variation_weight;
+ALTER TABLE llx_product_attribute ADD COLUMN ref_ext varchar(255) AFTER ref;
+ALTER TABLE llx_product_attribute_combination ADD COLUMN variation_ref_ext varchar(255) AFTER variation_weight;
From b841a4354e04052040811c64599eba8e43784b59 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Fri, 4 Sep 2020 12:06:09 +0200
Subject: [PATCH 06/18] NEW ref_ext for Attributes
---
.../variants/class/ProductAttribute.class.php | 24 ++++++++++++-------
1 file changed, 16 insertions(+), 8 deletions(-)
diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php
index 6e2335c2f99..d7fbbfefa8b 100644
--- a/htdocs/variants/class/ProductAttribute.class.php
+++ b/htdocs/variants/class/ProductAttribute.class.php
@@ -40,6 +40,12 @@ class ProductAttribute extends CommonObject
* @var string
*/
public $ref;
+
+ /**
+ * External ref of the product attribute
+ * @var string
+ */
+ public $ref_ext;
/**
* Label of the product attribute
@@ -79,8 +85,8 @@ class ProductAttribute extends CommonObject
return -1;
}
- $sql = "SELECT rowid, ref, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")";
-
+ $sql = "SELECT rowid, ref, ref_ext, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")";
+
$query = $this->db->query($sql);
if (!$this->db->num_rows($query)) {
@@ -91,6 +97,7 @@ class ProductAttribute extends CommonObject
$this->id = $obj->rowid;
$this->ref = $obj->ref;
+ $this->ref_ext = $obj->ref_ext;
$this->label = $obj->label;
$this->rang = $obj->rang;
@@ -106,7 +113,7 @@ class ProductAttribute extends CommonObject
{
$return = array();
- $sql = 'SELECT rowid, ref, label, rang FROM '.MAIN_DB_PREFIX."product_attribute WHERE entity IN (".getEntity('product').')';
+ $sql = 'SELECT rowid, ref, ref_ext, label, rang FROM '.MAIN_DB_PREFIX."product_attribute WHERE entity IN (".getEntity('product').')';
$sql .= $this->db->order('rang', 'asc');
$query = $this->db->query($sql);
if ($query)
@@ -115,6 +122,7 @@ class ProductAttribute extends CommonObject
$tmp = new ProductAttribute($this->db);
$tmp->id = $result->rowid;
$tmp->ref = $result->ref;
+ $tmp->ref_ext = $result->ref_ext;
$tmp->label = $result->label;
$tmp->rang = $result->rang;
@@ -147,9 +155,9 @@ class ProductAttribute extends CommonObject
//Ref must be uppercase
$this->ref = strtoupper($this->ref);
- $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_attribute (ref, label, entity, rang)
- VALUES ('".$this->db->escape($this->ref)."', '".$this->db->escape($this->label)."', ".(int) $this->entity.", ".(int) $this->rang.")";
-
+ $sql = "INSERT INTO ".MAIN_DB_PREFIX."product_attribute (ref, ref_ext, label, entity, rang)
+ VALUES ('".$this->db->escape($this->ref)."', '".$this->db->escape($this->ref_ext)."', '".$this->db->escape($this->label)."', ".(int) $this->entity.", ".(int) $this->rang.")";
+
$query = $this->db->query($sql);
if ($query)
{
@@ -183,8 +191,8 @@ class ProductAttribute extends CommonObject
$this->ref = trim(strtoupper($this->ref));
$this->label = trim($this->label);
- $sql = "UPDATE ".MAIN_DB_PREFIX."product_attribute SET ref = '".$this->db->escape($this->ref)."', label = '".$this->db->escape($this->label)."', rang = ".(int) $this->rang." WHERE rowid = ".(int) $this->id;
-
+ $sql = "UPDATE ".MAIN_DB_PREFIX."product_attribute SET ref = '".$this->db->escape($this->ref)."', ref_ext = '".$this->db->escape($this->ref_ext)."', label = '".$this->db->escape($this->label)."', rang = ".(int) $this->rang." WHERE rowid = ".(int) $this->id;
+
if ($this->db->query($sql)) {
return 1;
}
From 8d6c19a4328740ee99185fc65530122ec4e9cade Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Fri, 4 Sep 2020 10:10:37 +0000
Subject: [PATCH 07/18] Fixing style errors.
---
htdocs/variants/class/ProductAttribute.class.php | 8 ++++----
htdocs/variants/class/ProductCombination.class.php | 2 +-
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php
index d7fbbfefa8b..8ae9879e6ca 100644
--- a/htdocs/variants/class/ProductAttribute.class.php
+++ b/htdocs/variants/class/ProductAttribute.class.php
@@ -40,7 +40,7 @@ class ProductAttribute extends CommonObject
* @var string
*/
public $ref;
-
+
/**
* External ref of the product attribute
* @var string
@@ -86,7 +86,7 @@ class ProductAttribute extends CommonObject
}
$sql = "SELECT rowid, ref, ref_ext, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE rowid = ".(int) $id." AND entity IN (".getEntity('product').")";
-
+
$query = $this->db->query($sql);
if (!$this->db->num_rows($query)) {
@@ -157,7 +157,7 @@ class ProductAttribute extends CommonObject
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_attribute (ref, ref_ext, label, entity, rang)
VALUES ('".$this->db->escape($this->ref)."', '".$this->db->escape($this->ref_ext)."', '".$this->db->escape($this->label)."', ".(int) $this->entity.", ".(int) $this->rang.")";
-
+
$query = $this->db->query($sql);
if ($query)
{
@@ -192,7 +192,7 @@ class ProductAttribute extends CommonObject
$this->label = trim($this->label);
$sql = "UPDATE ".MAIN_DB_PREFIX."product_attribute SET ref = '".$this->db->escape($this->ref)."', ref_ext = '".$this->db->escape($this->ref_ext)."', label = '".$this->db->escape($this->label)."', rang = ".(int) $this->rang." WHERE rowid = ".(int) $this->id;
-
+
if ($this->db->query($sql)) {
return 1;
}
diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php
index a4faa6121a0..b65957d0a89 100644
--- a/htdocs/variants/class/ProductCombination.class.php
+++ b/htdocs/variants/class/ProductCombination.class.php
@@ -76,7 +76,7 @@ class ProductCombination
* @var ProductCombinationLevel[]
*/
public $combination_price_levels;
-
+
/**
* External ref
* @var string
From 4383f1d00c0188f1eb53a2ae2a9183475e110400 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 13:50:22 +0200
Subject: [PATCH 08/18] Update ProductCombination.class.php
---
htdocs/variants/class/ProductCombination.class.php | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php
index b65957d0a89..a449ca5d237 100644
--- a/htdocs/variants/class/ProductCombination.class.php
+++ b/htdocs/variants/class/ProductCombination.class.php
@@ -234,10 +234,10 @@ class ProductCombination
}
/**
- * Get fk_product_parent by fk_product_child
+ * Return the product id of the parent product of a variant product (Get fk_product_parent by fk_product_child)
*
- * @param int $fk_child Product row id
- * @return int >0 OK <0 KO
+ * @param int $fk_child Product row id
+ * @return int >0 if OK, 0 if product is not a variant, <0 if KO
*/
public function getFkProductParentByFkProductChild($fk_child)
{
@@ -251,7 +251,7 @@ class ProductCombination
}
if (!$this->db->num_rows($query)) {
- return -1;
+ return 0;
}
$row = $this->db->fetch_object($query);
From 0a09284b8fbaa1c9608a485f1b497acdffedd582 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Fri, 4 Sep 2020 21:32:12 +0200
Subject: [PATCH 09/18] FIX one time is enough
---
htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 3 ---
1 file changed, 3 deletions(-)
diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql
index 35f2e4e8a54..7dfccac5beb 100644
--- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql
+++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql
@@ -312,6 +312,3 @@ ALTER TABLE llx_inventorydet ADD UNIQUE uk_inventorydet(fk_inventory, fk_warehou
ALTER TABLE llx_product_attribute ADD COLUMN ref_ext varchar(255) AFTER ref;
ALTER TABLE llx_product_attribute_combination ADD COLUMN variation_ref_ext varchar(255) AFTER variation_weight;
-
-ALTER TABLE llx_product_attribute ADD COLUMN ref_ext varchar(255) AFTER ref;
-ALTER TABLE llx_product_attribute_combination ADD COLUMN variation_ref_ext varchar(255) AFTER variation_weight;
From 76a5a42191385172107d35b0c9ac9d79846093cf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Fri, 4 Sep 2020 23:07:10 +0200
Subject: [PATCH 10/18] Update llx_product_attribute.sql
---
htdocs/install/mysql/tables/llx_product_attribute.sql | 1 +
1 file changed, 1 insertion(+)
diff --git a/htdocs/install/mysql/tables/llx_product_attribute.sql b/htdocs/install/mysql/tables/llx_product_attribute.sql
index f7ebee3cc23..7e00b14d17a 100644
--- a/htdocs/install/mysql/tables/llx_product_attribute.sql
+++ b/htdocs/install/mysql/tables/llx_product_attribute.sql
@@ -20,6 +20,7 @@ CREATE TABLE llx_product_attribute
(
rowid INT PRIMARY KEY NOT NULL AUTO_INCREMENT,
ref VARCHAR(255) NOT NULL,
+ ref_ext varchar(255) DEFAULT NULL,
label VARCHAR(255) NOT NULL,
rang INT DEFAULT 0 NOT NULL,
entity INT DEFAULT 1 NOT NULL
From 806cfa84e258d509673140d36a05e66afad74084 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Fri, 4 Sep 2020 23:08:02 +0200
Subject: [PATCH 11/18] Update llx_product_attribute_combination.sql
---
.../install/mysql/tables/llx_product_attribute_combination.sql | 1 +
1 file changed, 1 insertion(+)
diff --git a/htdocs/install/mysql/tables/llx_product_attribute_combination.sql b/htdocs/install/mysql/tables/llx_product_attribute_combination.sql
index a00b4009c72..afbb9bcec65 100644
--- a/htdocs/install/mysql/tables/llx_product_attribute_combination.sql
+++ b/htdocs/install/mysql/tables/llx_product_attribute_combination.sql
@@ -25,5 +25,6 @@ CREATE TABLE llx_product_attribute_combination
variation_price DOUBLE(24,8) NOT NULL,
variation_price_percentage INTEGER NULL,
variation_weight REAL NOT NULL,
+ ref_ext varchar(255) DEFAULT NULL,
entity INTEGER DEFAULT 1 NOT NULL
)ENGINE=innodb;
From af910135061136e0987a72fdde21d2aa67e04d45 Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Sun, 6 Sep 2020 15:52:02 +0000
Subject: [PATCH 12/18] Fixing style errors.
---
.../class/ProductCombination.class.php | 104 +++++++++---------
1 file changed, 52 insertions(+), 52 deletions(-)
diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php
index e9e71b41c4a..cdf8e470a00 100644
--- a/htdocs/variants/class/ProductCombination.class.php
+++ b/htdocs/variants/class/ProductCombination.class.php
@@ -233,72 +233,72 @@ class ProductCombination
}
}
- /**
- * Return the product id of the parent product of a variant product (Get fk_product_parent by fk_product_child)
- *
- * @param int $fk_child Product row id
- * @return int >0 if OK, 0 if product is not a variant, <0 if KO
- */
- public function getFkProductParentByFkProductChild($fk_child)
- {
- $sql = "SELECT fk_product_parent FROM ".MAIN_DB_PREFIX."product_attribute_combination";
- $sql .= " WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').") LIMIT 1";
+ /**
+ * Return the product id of the parent product of a variant product (Get fk_product_parent by fk_product_child)
+ *
+ * @param int $fk_child Product row id
+ * @return int >0 if OK, 0 if product is not a variant, <0 if KO
+ */
+ public function getFkProductParentByFkProductChild($fk_child)
+ {
+ $sql = "SELECT fk_product_parent FROM ".MAIN_DB_PREFIX."product_attribute_combination";
+ $sql .= " WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').") LIMIT 1";
- $query = $this->db->query($sql);
+ $query = $this->db->query($sql);
- if (!$query) {
- return -1;
- }
+ if (!$query) {
+ return -1;
+ }
- if (!$this->db->num_rows($query)) {
- return 0;
- }
+ if (!$this->db->num_rows($query)) {
+ return 0;
+ }
- $row = $this->db->fetch_object($query);
+ $row = $this->db->fetch_object($query);
- return (int) $row->fk_product_parent;
- }
+ return (int) $row->fk_product_parent;
+ }
- /**
- * Retrieves all product combinations by the child product row id
- *
- * @param int $fk_child Product row id
- * @param int $donotloadpricelevel Avoid loading price impact for each level. If PRODUIT_MULTIPRICES is not set, this has no effect.
- * @return int|ProductCombination[] <0 KO
- */
- public function fetchAllByFkProductChild($fk_child, $donotloadpricelevel = 0)
- {
- global $conf;
+ /**
+ * Retrieves all product combinations by the child product row id
+ *
+ * @param int $fk_child Product row id
+ * @param int $donotloadpricelevel Avoid loading price impact for each level. If PRODUIT_MULTIPRICES is not set, this has no effect.
+ * @return int|ProductCombination[] <0 KO
+ */
+ public function fetchAllByFkProductChild($fk_child, $donotloadpricelevel = 0)
+ {
+ global $conf;
- $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, variation_ref_ext FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').")";
+ $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, variation_ref_ext FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').")";
- $query = $this->db->query($sql);
+ $query = $this->db->query($sql);
- if (!$query) {
- return -1;
- }
+ if (!$query) {
+ return -1;
+ }
- $return = array();
+ $return = array();
- while ($result = $this->db->fetch_object($query)) {
- $tmp = new ProductCombination($this->db);
- $tmp->id = $result->rowid;
- $tmp->fk_product_parent = $result->fk_product_parent;
- $tmp->fk_product_child = $result->fk_product_child;
- $tmp->variation_price = $result->variation_price;
- $tmp->variation_price_percentage = $result->variation_price_percentage;
- $tmp->variation_weight = $result->variation_weight;
- $tmp->variation_ref_ext = $result->variation_ref_ext;
+ while ($result = $this->db->fetch_object($query)) {
+ $tmp = new ProductCombination($this->db);
+ $tmp->id = $result->rowid;
+ $tmp->fk_product_parent = $result->fk_product_parent;
+ $tmp->fk_product_child = $result->fk_product_child;
+ $tmp->variation_price = $result->variation_price;
+ $tmp->variation_price_percentage = $result->variation_price_percentage;
+ $tmp->variation_weight = $result->variation_weight;
+ $tmp->variation_ref_ext = $result->variation_ref_ext;
- if (empty($donotloadpricelevel) && !empty($conf->global->PRODUIT_MULTIPRICES)) {
- $tmp->fetchCombinationPriceLevels();
- }
+ if (empty($donotloadpricelevel) && !empty($conf->global->PRODUIT_MULTIPRICES)) {
+ $tmp->fetchCombinationPriceLevels();
+ }
- $return[] = $tmp;
- }
+ $return[] = $tmp;
+ }
- return $return;
- }
+ return $return;
+ }
/**
* Retrieves all product combinations by the product parent row id
From 61903a10795279ec58dcc4f9d43bafbf42b968e2 Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Mon, 7 Sep 2020 15:24:35 +0000
Subject: [PATCH 13/18] Fixing style errors.
---
htdocs/product/card.php | 6 +++---
htdocs/product/class/product.class.php | 2 +-
.../variants/class/ProductAttribute.class.php | 18 +++++++++---------
3 files changed, 13 insertions(+), 13 deletions(-)
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 7195c1476f3..073136e8807 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -1912,9 +1912,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
if (!empty($conf->variants->enabled) && ($object->isProduct() || $object->isService())) {
$combination = new ProductCombination($db);
- if (($fk_product_parent = $combination->getFkProductParentByFkProductChild($object->id)) > 0) {
- $prodstatic = new Product($db);
- $prodstatic->fetch($fk_product_parent);
+ if (($fk_product_parent = $combination->getFkProductParentByFkProductChild($object->id)) > 0) {
+ $prodstatic = new Product($db);
+ $prodstatic->fetch($fk_product_parent);
// Parent product
print '| '.$langs->trans("ParentProduct").' | ';
diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php
index fb27e140cc2..697c51f09c4 100644
--- a/htdocs/product/class/product.class.php
+++ b/htdocs/product/class/product.class.php
@@ -4482,7 +4482,7 @@ class Product extends CommonObject
global $conf, $langs;
$labelStatus = $labelStatusShort = '';
-
+
$langs->load('products');
if (!empty($conf->productbatch->enabled)) { $langs->load("productbatch");
}
diff --git a/htdocs/variants/class/ProductAttribute.class.php b/htdocs/variants/class/ProductAttribute.class.php
index 533fc7ea9f4..bbc3a188137 100644
--- a/htdocs/variants/class/ProductAttribute.class.php
+++ b/htdocs/variants/class/ProductAttribute.class.php
@@ -118,16 +118,16 @@ class ProductAttribute extends CommonObject
$query = $this->db->query($sql);
if ($query)
{
- while ($result = $this->db->fetch_object($query)) {
- $tmp = new ProductAttribute($this->db);
- $tmp->id = $result->rowid;
- $tmp->ref = $result->ref;
- $tmp->ref_ext = $result->ref_ext;
- $tmp->label = $result->label;
- $tmp->rang = $result->rang;
+ while ($result = $this->db->fetch_object($query)) {
+ $tmp = new ProductAttribute($this->db);
+ $tmp->id = $result->rowid;
+ $tmp->ref = $result->ref;
+ $tmp->ref_ext = $result->ref_ext;
+ $tmp->label = $result->label;
+ $tmp->rang = $result->rang;
- $return[] = $tmp;
- }
+ $return[] = $tmp;
+ }
}
else dol_print_error($this->db);
From efb59754d72b62c586f51e1e802952d844e6bd03 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Wed, 9 Sep 2020 19:32:14 +0200
Subject: [PATCH 14/18] Update 12.0.0-13.0.0.sql
---
htdocs/install/mysql/migration/12.0.0-13.0.0.sql | 3 ---
1 file changed, 3 deletions(-)
diff --git a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql
index 37fcf0d785f..a41b6825fa3 100644
--- a/htdocs/install/mysql/migration/12.0.0-13.0.0.sql
+++ b/htdocs/install/mysql/migration/12.0.0-13.0.0.sql
@@ -312,8 +312,5 @@ ALTER TABLE llx_actioncomm_reminder ADD INDEX idx_actioncomm_reminder_status (st
ALTER TABLE llx_inventorydet ADD UNIQUE uk_inventorydet(fk_inventory, fk_warehouse, fk_product, batch);
-ALTER TABLE llx_product_attribute ADD COLUMN ref_ext varchar(255) AFTER ref;
-ALTER TABLE llx_product_attribute_combination ADD COLUMN variation_ref_ext varchar(255) AFTER variation_weight;
-
ALTER TABLE llx_commandedet ADD COLUMN ref_ext varchar(255) AFTER label;
ALTER TABLE llx_facturedet ADD COLUMN ref_ext varchar(255) AFTER multicurrency_total_ttc;
From 3209708e309d79bfa62c0e18dd136cbf7a415d71 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Thu, 10 Sep 2020 13:56:58 +0200
Subject: [PATCH 15/18] Update ProductCombination.class.php
---
htdocs/variants/class/ProductCombination.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php
index 6510ef3176e..bd593b2c568 100644
--- a/htdocs/variants/class/ProductCombination.class.php
+++ b/htdocs/variants/class/ProductCombination.class.php
@@ -373,7 +373,7 @@ class ProductCombination
/* $this->fk_product_child may be empty and will be filled later after subproduct has been created */
$sql = "INSERT INTO ".MAIN_DB_PREFIX."product_attribute_combination";
- $sql .= " (fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, entity)";
+ $sql .= " (fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, variation_ref_ext, entity)";
$sql .= " VALUES (".((int) $this->fk_product_parent).", ".((int) $this->fk_product_child).",";
$sql .= (float) $this->variation_price.", ".(int) $this->variation_price_percentage.",";
$sql .= (float) $this->variation_weight.", '".$this->db->escape($this->variation_ref_ext)."', ".(int) $this->entity.")";
From e711ab3aa398f5fad429b1f27ef9cb1b7b454bbc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Thu, 17 Sep 2020 12:31:56 +0200
Subject: [PATCH 16/18] Update product.lib.php
---
htdocs/core/lib/product.lib.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/core/lib/product.lib.php b/htdocs/core/lib/product.lib.php
index 686ff3af1f5..dfc57313add 100644
--- a/htdocs/core/lib/product.lib.php
+++ b/htdocs/core/lib/product.lib.php
@@ -107,7 +107,7 @@ function product_prepare_head($object)
$prodcomb = new ProductCombination($db);
- if ($prodcomb->getFkProductParentByFkProductChild($object->id) == -1)
+ if ($prodcomb->fetchByFkProductChild($object->id) == -1)
{
$head[$h][0] = DOL_URL_ROOT."/variants/combinations.php?id=".$object->id;
$head[$h][1] = $langs->trans('ProductCombinations');
From 67b565df6ba5a0aa59a5302b43908827fd14712f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Thu, 17 Sep 2020 12:34:47 +0200
Subject: [PATCH 17/18] Update card.php
---
htdocs/product/card.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/product/card.php b/htdocs/product/card.php
index 073136e8807..df3f21a453a 100644
--- a/htdocs/product/card.php
+++ b/htdocs/product/card.php
@@ -1912,9 +1912,9 @@ if (is_object($objcanvas) && $objcanvas->displayCanvasExists($action))
if (!empty($conf->variants->enabled) && ($object->isProduct() || $object->isService())) {
$combination = new ProductCombination($db);
- if (($fk_product_parent = $combination->getFkProductParentByFkProductChild($object->id)) > 0) {
+ if ($combination->fetchByFkProductChild($object->id) > 0) {
$prodstatic = new Product($db);
- $prodstatic->fetch($fk_product_parent);
+ $prodstatic->fetch($combination->fk_product_parent);
// Parent product
print '| '.$langs->trans("ParentProduct").' | ';
From 0d20b6645d95d726d815f399396cf6bb07c21bdc Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?C=C3=A9dric?= <35066297+c3do@users.noreply.github.com>
Date: Thu, 17 Sep 2020 12:37:20 +0200
Subject: [PATCH 18/18] Update ProductCombination.class.php
---
.../class/ProductCombination.class.php | 65 ++++++-------------
1 file changed, 19 insertions(+), 46 deletions(-)
diff --git a/htdocs/variants/class/ProductCombination.class.php b/htdocs/variants/class/ProductCombination.class.php
index bd593b2c568..a50256226f3 100644
--- a/htdocs/variants/class/ProductCombination.class.php
+++ b/htdocs/variants/class/ProductCombination.class.php
@@ -234,15 +234,18 @@ class ProductCombination
}
/**
- * Return the product id of the parent product of a variant product (Get fk_product_parent by fk_product_child)
+ * Retrieves information of a variant product and ID of its parent product.
*
- * @param int $fk_child Product row id
- * @return int >0 if OK, 0 if product is not a variant, <0 if KO
+ * @param int $productid Product ID of variant
+ * @param int $donotloadpricelevel Avoid loading price impact for each level. If PRODUIT_MULTIPRICES is not set, this has no effect.
+ * @return int <0 if KO, 0 if product ID is not ID of a variant product (so parent not found), >0 if OK (ID of parent)
*/
- public function getFkProductParentByFkProductChild($fk_child)
+ public function fetchByFkProductChild($productid, $donotloadpricelevel = 0)
{
- $sql = "SELECT fk_product_parent FROM ".MAIN_DB_PREFIX."product_attribute_combination";
- $sql .= " WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').") LIMIT 1";
+ global $conf;
+
+ $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight";
+ $sql .= " FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".((int) $productid)." AND entity IN (".getEntity('product').")";
$query = $this->db->query($sql);
@@ -254,50 +257,20 @@ class ProductCombination
return 0;
}
- $row = $this->db->fetch_object($query);
+ $result = $this->db->fetch_object($query);
- return (int) $row->fk_product_parent;
- }
+ $this->id = $result->rowid;
+ $this->fk_product_parent = $result->fk_product_parent;
+ $this->fk_product_child = $result->fk_product_child;
+ $this->variation_price = $result->variation_price;
+ $this->variation_price_percentage = $result->variation_price_percentage;
+ $this->variation_weight = $result->variation_weight;
- /**
- * Retrieves all product combinations by the child product row id
- *
- * @param int $fk_child Product row id
- * @param int $donotloadpricelevel Avoid loading price impact for each level. If PRODUIT_MULTIPRICES is not set, this has no effect.
- * @return int|ProductCombination[] <0 KO
- */
- public function fetchAllByFkProductChild($fk_child, $donotloadpricelevel = 0)
- {
- global $conf;
-
- $sql = "SELECT rowid, fk_product_parent, fk_product_child, variation_price, variation_price_percentage, variation_weight, variation_ref_ext FROM ".MAIN_DB_PREFIX."product_attribute_combination WHERE fk_product_child = ".(int) $fk_child." AND entity IN (".getEntity('product').")";
-
- $query = $this->db->query($sql);
-
- if (!$query) {
- return -1;
+ if (empty($donotloadpricelevel) && !empty($conf->global->PRODUIT_MULTIPRICES)) {
+ $this->fetchCombinationPriceLevels();
}
- $return = array();
-
- while ($result = $this->db->fetch_object($query)) {
- $tmp = new ProductCombination($this->db);
- $tmp->id = $result->rowid;
- $tmp->fk_product_parent = $result->fk_product_parent;
- $tmp->fk_product_child = $result->fk_product_child;
- $tmp->variation_price = $result->variation_price;
- $tmp->variation_price_percentage = $result->variation_price_percentage;
- $tmp->variation_weight = $result->variation_weight;
- $tmp->variation_ref_ext = $result->variation_ref_ext;
-
- if (empty($donotloadpricelevel) && !empty($conf->global->PRODUIT_MULTIPRICES)) {
- $tmp->fetchCombinationPriceLevels();
- }
-
- $return[] = $tmp;
- }
-
- return $return;
+ return (int) $this->fk_product_parent;
}
/**
| | |