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 001/318] 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 002/318] 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 003/318] 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 004/318] 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 005/318] 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 006/318] 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 007/318] 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 704b83c79a2384cb4e0a17f383ddecaefe504ad0 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:24:57 +0200
Subject: [PATCH 008/318] Multiple fix and features
NEW ref_ext for Attributes and Combinations
Clean and improved results for ::getAttributeValues ::getAttributes ::getAttributesById ::getAttributesByRef
FIX delete subproduct endpoint url
---
htdocs/product/class/api_products.class.php | 163 ++++++++++++++++++--
1 file changed, 153 insertions(+), 10 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index f1b3e91617b..f2aeba7f171 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -455,7 +455,7 @@ class Products extends DolibarrApi
* @throws RestException 401
* @throws RestException 404
*
- * @url DELETE {id}/subproducts/remove
+ * @url DELETE {id}/subproducts/remove/{subproduct_id}
*/
public function delSubproducts($id, $subproduct_id)
{
@@ -878,21 +878,70 @@ class Products extends DolibarrApi
/**
* Get attributes.
- *
+ * @param string $sortfield Sort field
+ * @param string $sortorder Sort order
+ * @param int $limit Limit for list
+ * @param int $page Page number
+ * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:color)"
* @return array
*
* @throws RestException
*
* @url GET attributes
*/
- public function getAttributes()
+ public function getAttributes($sortfield = "t.ref", $sortorder = 'ASC', $limit = 100, $page = 0, $sqlfilters = '')
{
if (!DolibarrApiAccess::$user->rights->produit->lire) {
throw new RestException(401);
}
- $prodattr = new ProductAttribute($this->db);
- return $prodattr->fetchAll();
+ $sql = "SELECT t.rowid, t.ref, t.ref_ext, t.label, t.rang, t.entity";
+ $sql .= " FROM ".MAIN_DB_PREFIX."product_attribute as t";
+ $sql .= ' WHERE t.entity IN ('.getEntity('product_attribute').')';
+
+ // Add sql filters
+ if ($sqlfilters) {
+ if (!DolibarrApi::_checkFilters($sqlfilters)) {
+ throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters);
+ }
+ $regexstring = '\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)';
+ $sql .= " AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")";
+ }
+
+ $sql .= $this->db->order($sortfield, $sortorder);
+ if ($limit) {
+ if ($page < 0) {
+ $page = 0;
+ }
+ $offset = $limit * $page;
+
+ $sql .= $this->db->plimit($limit, $offset);
+ }
+
+ $result = $this->db->query($sql);
+
+ if (!$result) {
+ throw new RestException(503, 'Error when retrieve product list : '.$db->lasterror());
+ }
+
+ $return = [];
+ while ($result = $this->db->fetch_object($query)) {
+ $tmp = new stdClass();
+ $tmp->id = $result->rowid;
+ $tmp->ref = $result->ref;
+ $tmp->ref_ext = $result->ref_ext;
+ $tmp->label = $result->label;
+ $tmp->rang = $result->rang;
+ $tmp->entity = $result->entity;
+
+ $return[] = $tmp;
+ }
+
+ if (!count($return)) {
+ throw new RestException(404, 'No product attribute found');
+ }
+
+ return $return;
}
/**
@@ -920,6 +969,22 @@ class Products extends DolibarrApi
throw new RestException(404, "Attribute not found");
}
+ $fields = ["id", "ref", "ref_ext", "label", "rang"];
+
+ foreach ($prodattr as $field => $value) {
+ if (!in_array($field, $fields)) {
+ unset($prodattr->{$field});
+ }
+ }
+
+ $sql = "SELECT COUNT(*) count FROM ".MAIN_DB_PREFIX."product_attribute_combination2val pac2v";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac2v.fk_prod_combination = pac.rowid";
+ $sql .= " WHERE pac2v.fk_prod_attr = ".(int) $prodattr->id." AND pac.entity IN (".getEntity('product').")";
+ $query = $this->db->query($sql);
+ $result = $this->db->fetch_object($query);
+
+ $prodattr->is_used_by_products = (bool) $result->count;
+
return $prodattr;
}
@@ -940,7 +1005,7 @@ class Products extends DolibarrApi
throw new RestException(401);
}
- $sql = "SELECT rowid, ref, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")";
+ $sql = "SELECT rowid, ref, ref_ext, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")";
$query = $this->db->query($sql);
@@ -953,9 +1018,63 @@ class Products extends DolibarrApi
$attr = [];
$attr['id'] = $result->rowid;
$attr['ref'] = $result->ref;
+ $attr['ref_ext'] = $result->ref_ext;
$attr['label'] = $result->label;
$attr['rang'] = $result->rang;
+ $sql = "SELECT COUNT(*) count FROM ".MAIN_DB_PREFIX."product_attribute_combination2val pac2v";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac2v.fk_prod_combination = pac.rowid";
+ $sql .= " WHERE pac2v.fk_prod_attr = ".(int) $result->rowid." AND pac.entity IN (".getEntity('product').")";
+ $query = $this->db->query($sql);
+ $result = $this->db->fetch_object($query);
+
+ $attr["is_used_by_products"] = (bool) $result->count;
+
+ return $attr;
+ }
+
+ /**
+ * Get attributes by ref_ext.
+ *
+ * @param string $ref_ext External reference of Attribute
+ * @return array
+ *
+ * @throws RestException 500
+ * @throws RestException 401
+ *
+ * @url GET attributes/ref_ext/{ref_ext}
+ */
+ public function getAttributesByRefExt($ref_ext)
+ {
+ if (!DolibarrApiAccess::$user->rights->produit->lire) {
+ throw new RestException(401);
+ }
+
+ $sql = "SELECT rowid, ref, ref_ext, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref_ext LIKE '".trim($ref_ext)."' AND entity IN (".getEntity('product').")";
+
+ $query = $this->db->query($sql);
+
+ if (!$this->db->num_rows($query)) {
+ throw new RestException(404);
+ }
+
+ $result = $this->db->fetch_object($query);
+
+ $attr = [];
+ $attr['id'] = $result->rowid;
+ $attr['ref'] = $result->ref;
+ $attr['ref_ext'] = $result->ref_ext;
+ $attr['label'] = $result->label;
+ $attr['rang'] = $result->rang;
+
+ $sql = "SELECT COUNT(*) count FROM ".MAIN_DB_PREFIX."product_attribute_combination2val pac2v";
+ $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac2v.fk_prod_combination = pac.rowid";
+ $sql .= " WHERE pac2v.fk_prod_attr = ".(int) $result->rowid." AND pac.entity IN (".getEntity('product').")";
+ $query = $this->db->query($sql);
+ $result = $this->db->fetch_object($query);
+
+ $attr["is_used_by_products"] = (bool) $result->count;
+
return $attr;
}
@@ -964,6 +1083,7 @@ class Products extends DolibarrApi
*
* @param string $ref Reference of Attribute
* @param string $label Label of Attribute
+ * @param string $ref_ext Reference of Attribute
* @return int
*
* @throws RestException 500
@@ -971,7 +1091,7 @@ class Products extends DolibarrApi
*
* @url POST attributes
*/
- public function addAttributes($ref, $label)
+ public function addAttributes($ref, $label, $ref_ext = '')
{
if (!DolibarrApiAccess::$user->rights->produit->creer) {
throw new RestException(401);
@@ -980,6 +1100,7 @@ class Products extends DolibarrApi
$prodattr = new ProductAttribute($this->db);
$prodattr->label = $label;
$prodattr->ref = $ref;
+ $prodattr->ref_ext = $ref_ext;
$resid = $prodattr->create(DolibarrApiAccess::$user);
if ($resid <= 0) {
@@ -1202,7 +1323,22 @@ class Products extends DolibarrApi
}
$objectval = new ProductAttributeValue($this->db);
- return $objectval->fetchAllByProductAttribute((int) $id);
+
+ $return = [];
+ foreach ($objectval->fetchAllByProductAttribute((int) $id) as $result) {
+ $tmp = new stdClass();
+ $tmp->fk_product_attribute = (int) $result->fk_product_attribute;
+ $tmp->id = (int) $result->id;
+ $tmp->ref = $result->ref;
+ $tmp->value = $result->value;
+ $return[] = $tmp;
+ }
+
+ if (count($return) == 0) {
+ throw new RestException(404, 'Attribute values not found');
+ }
+
+ return $return;
}
/**
@@ -1420,6 +1556,7 @@ class Products extends DolibarrApi
* @param bool $price_impact_is_percent Price impact in percent (true or false)
* @param array $features List of attributes pairs id_attribute->id_value. Example: array(id_color=>id_Blue, id_size=>id_small, id_option=>id_val_a, ...)
* @param bool|string $reference Customized reference of variant
+ * @param string $ref_ext External reference of variant
* @return int
*
* @throws RestException 500
@@ -1428,7 +1565,7 @@ class Products extends DolibarrApi
*
* @url POST {id}/variants
*/
- public function addVariant($id, $weight_impact, $price_impact, $price_impact_is_percent, $features, $reference = false)
+ public function addVariant($id, $weight_impact, $price_impact, $price_impact_is_percent, $features, $reference = false, $ref_ext = '')
{
if (!DolibarrApiAccess::$user->rights->produit->creer) {
throw new RestException(401);
@@ -1459,7 +1596,7 @@ class Products extends DolibarrApi
$prodcomb = new ProductCombination($this->db);
- $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact, $reference);
+ $result = $prodcomb->createProductCombination(DolibarrApiAccess::$user, $this->product, $features, array(), $price_impact_is_percent, $price_impact, $weight_impact, $reference, $ref_ext);
if ($result > 0)
{
return $result;
@@ -1678,6 +1815,12 @@ class Products extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
+ $prodcomb = new ProductCombination($this->db);
+ $this->product->fk_product_parent = null;
+ if (($fk_product_parent = $prodcomb->getFkProductParentByFkProductChild($this->product->id)) > 0) {
+ $this->product->fk_product_parent = $fk_product_parent;
+ }
+
if ($includestockdata) {
$this->product->load_stock();
From e5633e07a28ede6d83b594a1693c6a096832b3ea Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 12:28:47 +0200
Subject: [PATCH 009/318] Update api_products.class.php
---
htdocs/product/class/api_products.class.php | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index f2aeba7f171..9868835414a 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -445,8 +445,7 @@ class Products extends DolibarrApi
/**
* Remove subproduct.
- *
- * Unlink a product/service from a parent product/service
+ * Unlink a product/service from a parent product/service
*
* @param int $id Id of parent product/service
* @param int $subproduct_id Id of child product/service
From b329a9d8863ab96aa0b750725634b20f7f010f00 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 12:45:09 +0200
Subject: [PATCH 010/318] Update api_products.class.php
---
htdocs/product/class/api_products.class.php | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 9868835414a..1fda9bf3a22 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -877,6 +877,7 @@ class Products extends DolibarrApi
/**
* Get attributes.
+ *
* @param string $sortfield Sort field
* @param string $sortorder Sort order
* @param int $limit Limit for list
@@ -920,12 +921,12 @@ class Products extends DolibarrApi
$result = $this->db->query($sql);
if (!$result) {
- throw new RestException(503, 'Error when retrieve product list : '.$db->lasterror());
+ throw new RestException(503, 'Error when retrieve product attribute list : '.$db->lasterror());
}
$return = [];
while ($result = $this->db->fetch_object($query)) {
- $tmp = new stdClass();
+ $tmp = new ProductAttribute($this->db);
$tmp->id = $result->rowid;
$tmp->ref = $result->ref;
$tmp->ref_ext = $result->ref_ext;
From 8ca08de5e6c7b04db2364b81cdc44ddc830cca7a Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 12:51:44 +0200
Subject: [PATCH 011/318] Debug
---
htdocs/product/class/api_products.class.php | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 1fda9bf3a22..d903f8f7698 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -897,7 +897,7 @@ class Products extends DolibarrApi
$sql = "SELECT t.rowid, t.ref, t.ref_ext, t.label, t.rang, t.entity";
$sql .= " FROM ".MAIN_DB_PREFIX."product_attribute as t";
- $sql .= ' WHERE t.entity IN ('.getEntity('product_attribute').')';
+ $sql .= ' WHERE t.entity IN ('.getEntity('product').')';
// Add sql filters
if ($sqlfilters) {
@@ -966,10 +966,10 @@ class Products extends DolibarrApi
$result = $prodattr->fetch((int) $id);
if ($result < 0) {
- throw new RestException(404, "Attribute not found");
+ throw new RestException(404, "Product attribute not found");
}
- $fields = ["id", "ref", "ref_ext", "label", "rang"];
+ $fields = ["id", "ref", "ref_ext", "label", "rang", "entity"];
foreach ($prodattr as $field => $value) {
if (!in_array($field, $fields)) {
@@ -977,13 +977,13 @@ class Products extends DolibarrApi
}
}
- $sql = "SELECT COUNT(*) count FROM ".MAIN_DB_PREFIX."product_attribute_combination2val pac2v";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac2v.fk_prod_combination = pac.rowid";
- $sql .= " WHERE pac2v.fk_prod_attr = ".(int) $prodattr->id." AND pac.entity IN (".getEntity('product').")";
- $query = $this->db->query($sql);
- $result = $this->db->fetch_object($query);
-
- $prodattr->is_used_by_products = (bool) $result->count;
+ $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
+ $sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
+ $sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
+
+ $resql = $this->db->query($sql);
+ $obj = $this->db->fetch_object($resql);
+ $prodattr->is_used_by_products = (int) $obj->nb;
return $prodattr;
}
From 8026ee15dfdcfddcfa283370df71d76718439fee Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Fri, 4 Sep 2020 10:52:55 +0000
Subject: [PATCH 012/318] Fixing style errors.
---
htdocs/product/class/api_products.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index d903f8f7698..bd18fb3dfb4 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -980,7 +980,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$prodattr->is_used_by_products = (int) $obj->nb;
From 606217fefcdae69372589b0ce104ea31347f0276 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 12:54:23 +0200
Subject: [PATCH 013/318] Debug
---
htdocs/product/class/api_products.class.php | 18 ++++++++++--------
1 file changed, 10 insertions(+), 8 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index bd18fb3dfb4..15d6237339b 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -980,7 +980,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$prodattr->is_used_by_products = (int) $obj->nb;
@@ -1005,7 +1005,7 @@ class Products extends DolibarrApi
throw new RestException(401);
}
- $sql = "SELECT rowid, ref, ref_ext, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")";
+ $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."' AND entity IN (".getEntity('product').")";
$query = $this->db->query($sql);
@@ -1021,14 +1021,16 @@ class Products extends DolibarrApi
$attr['ref_ext'] = $result->ref_ext;
$attr['label'] = $result->label;
$attr['rang'] = $result->rang;
+ $attr['entity'] = $result->entity;
- $sql = "SELECT COUNT(*) count FROM ".MAIN_DB_PREFIX."product_attribute_combination2val pac2v";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac2v.fk_prod_combination = pac.rowid";
- $sql .= " WHERE pac2v.fk_prod_attr = ".(int) $result->rowid." AND pac.entity IN (".getEntity('product').")";
- $query = $this->db->query($sql);
- $result = $this->db->fetch_object($query);
+ $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
+ $sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
+ $sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
+
+ $resql = $this->db->query($sql);
+ $obj = $this->db->fetch_object($resql);
- $attr["is_used_by_products"] = (bool) $result->count;
+ $attr["is_used_by_products"] = (int) $obj->nb;
return $attr;
}
From 334224cd2d19e77f96c0f9b0a18d99cf6d10ccdf Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Fri, 4 Sep 2020 10:55:34 +0000
Subject: [PATCH 014/318] Fixing style errors.
---
htdocs/product/class/api_products.class.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 15d6237339b..3a97c798eca 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -980,7 +980,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$prodattr->is_used_by_products = (int) $obj->nb;
@@ -1026,7 +1026,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
From a6f6db6b545a785d3526647c2a3a728729d295de Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 12:56:06 +0200
Subject: [PATCH 015/318] Update api_products.class.php
---
htdocs/product/class/api_products.class.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 3a97c798eca..f66db145902 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -934,7 +934,7 @@ class Products extends DolibarrApi
$tmp->rang = $result->rang;
$tmp->entity = $result->entity;
- $return[] = $tmp;
+ $return[] = $this->_cleanObjectDatas($tmp);
}
if (!count($return)) {
@@ -980,7 +980,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$prodattr->is_used_by_products = (int) $obj->nb;
@@ -1026,7 +1026,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
From d6bf70300af75ae016551d5279b3cbe24f918360 Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Fri, 4 Sep 2020 10:57:21 +0000
Subject: [PATCH 016/318] Fixing style errors.
---
htdocs/product/class/api_products.class.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index f66db145902..151f95a84a6 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -980,7 +980,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$prodattr->is_used_by_products = (int) $obj->nb;
@@ -1026,7 +1026,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
From a93cbafe588572aca4a49e6340467dea4139bc30 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 12:58:30 +0200
Subject: [PATCH 017/318] Update api_products.class.php
---
htdocs/product/class/api_products.class.php | 21 +++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 151f95a84a6..ee02aea99ac 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -980,7 +980,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$prodattr->is_used_by_products = (int) $obj->nb;
@@ -1026,7 +1026,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
@@ -1052,7 +1052,7 @@ class Products extends DolibarrApi
throw new RestException(401);
}
- $sql = "SELECT rowid, ref, ref_ext, label, rang FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref_ext LIKE '".trim($ref_ext)."' AND entity IN (".getEntity('product').")";
+ $sql = "SELECT rowid, ref, ref_ext, label, rang, entity FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref_ext LIKE '".trim($ref_ext)."' AND entity IN (".getEntity('product').")";
$query = $this->db->query($sql);
@@ -1068,14 +1068,15 @@ class Products extends DolibarrApi
$attr['ref_ext'] = $result->ref_ext;
$attr['label'] = $result->label;
$attr['rang'] = $result->rang;
+ $attr['entity'] = $result->entity;
- $sql = "SELECT COUNT(*) count FROM ".MAIN_DB_PREFIX."product_attribute_combination2val pac2v";
- $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_attribute_combination pac ON pac2v.fk_prod_combination = pac.rowid";
- $sql .= " WHERE pac2v.fk_prod_attr = ".(int) $result->rowid." AND pac.entity IN (".getEntity('product').")";
- $query = $this->db->query($sql);
- $result = $this->db->fetch_object($query);
-
- $attr["is_used_by_products"] = (bool) $result->count;
+ $sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
+ $sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
+ $sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
+
+ $resql = $this->db->query($sql);
+ $obj = $this->db->fetch_object($resql);
+ $attr["is_used_by_products"] = (int) $obj->nb;
return $attr;
}
From 962bb0c698e36ae1fcceaddc1a97dde324872f2d Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Fri, 4 Sep 2020 10:59:38 +0000
Subject: [PATCH 018/318] Fixing style errors.
---
htdocs/product/class/api_products.class.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index ee02aea99ac..b4b4715ac11 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -980,7 +980,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $prodattr->id)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$prodattr->is_used_by_products = (int) $obj->nb;
@@ -1026,7 +1026,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
@@ -1073,7 +1073,7 @@ class Products extends DolibarrApi
$sql = "SELECT COUNT(*) as nb FROM ".MAIN_DB_PREFIX."product_attribute_combination2val as pac2v";
$sql .= " JOIN ".MAIN_DB_PREFIX."product_attribute_combination as pac ON pac2v.fk_prod_combination = pac.rowid";
$sql .= " WHERE pac2v.fk_prod_attr = ".((int) $result->rowid)." AND pac.entity IN (".getEntity('product').")";
-
+
$resql = $this->db->query($sql);
$obj = $this->db->fetch_object($resql);
$attr["is_used_by_products"] = (int) $obj->nb;
From a98c5b9841fb42b1bb81c1e869e2dc1dfd21cb1e Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 13:05:30 +0200
Subject: [PATCH 019/318] Update api_products.class.php
---
htdocs/product/class/api_products.class.php | 22 +++++++++------------
1 file changed, 9 insertions(+), 13 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index b4b4715ac11..a4726405669 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -1327,20 +1327,16 @@ class Products extends DolibarrApi
$objectval = new ProductAttributeValue($this->db);
- $return = [];
- foreach ($objectval->fetchAllByProductAttribute((int) $id) as $result) {
- $tmp = new stdClass();
- $tmp->fk_product_attribute = (int) $result->fk_product_attribute;
- $tmp->id = (int) $result->id;
- $tmp->ref = $result->ref;
- $tmp->value = $result->value;
- $return[] = $tmp;
- }
-
+ $return = $objectval->fetchAllByProductAttribute((int) $id);
+
if (count($return) == 0) {
throw new RestException(404, 'Attribute values not found');
}
+ foreach ($return as $key => $val) {
+ $return[$key] = $this->_cleanObjectDatas($return[$key]);
+ }
+
return $return;
}
@@ -1363,8 +1359,8 @@ class Products extends DolibarrApi
$return = array();
$sql = 'SELECT ';
- $sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value v ';
- $sql .= "WHERE v.fk_product_attribute = ( SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".strtoupper(trim($ref))."' LIMIT 1)";
+ $sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value as v';
+ $sql .= " WHERE v.fk_product_attribute = (SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".strtoupper(trim($ref))."' LIMIT 1)";
$query = $this->db->query($sql);
@@ -1375,7 +1371,7 @@ class Products extends DolibarrApi
$tmp->ref = $result->ref;
$tmp->value = $result->value;
- $return[] = $tmp;
+ $return[] = $this->_cleanObjectDatas($tmp);
}
return $return;
From 52c057b9dd8068277e6ecb7a6d224e3955333730 Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Fri, 4 Sep 2020 11:06:43 +0000
Subject: [PATCH 020/318] Fixing style errors.
---
htdocs/product/class/api_products.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index a4726405669..d27ac9ad836 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -1328,7 +1328,7 @@ class Products extends DolibarrApi
$objectval = new ProductAttributeValue($this->db);
$return = $objectval->fetchAllByProductAttribute((int) $id);
-
+
if (count($return) == 0) {
throw new RestException(404, 'Attribute values not found');
}
From 9cafd3b97f28d33ce3b2fdc660e98b04f08f6ab0 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 13:10:30 +0200
Subject: [PATCH 021/318] Update api_products.class.php
---
htdocs/product/class/api_products.class.php | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index d27ac9ad836..d5255bfa57f 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -1360,11 +1360,11 @@ class Products extends DolibarrApi
$sql = 'SELECT ';
$sql .= 'v.fk_product_attribute, v.rowid, v.ref, v.value FROM '.MAIN_DB_PREFIX.'product_attribute_value as v';
- $sql .= " WHERE v.fk_product_attribute = (SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".strtoupper(trim($ref))."' LIMIT 1)";
+ $sql .= " WHERE v.fk_product_attribute IN (SELECT rowid FROM ".MAIN_DB_PREFIX."product_attribute WHERE ref LIKE '".trim($ref)."')";
- $query = $this->db->query($sql);
+ $resql = $this->db->query($sql);
- while ($result = $this->db->fetch_object($query)) {
+ while ($result = $this->db->fetch_object($resql)) {
$tmp = new ProductAttributeValue($this->db);
$tmp->fk_product_attribute = $result->fk_product_attribute;
$tmp->id = $result->rowid;
From 8e2001a09bd222af87c8369f963e72bc5c6ee909 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 13:20:03 +0200
Subject: [PATCH 022/318] Update api_products.class.php
---
htdocs/product/class/api_products.class.php | 17 ++++++++++-------
1 file changed, 10 insertions(+), 7 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index d5255bfa57f..9721cd4a3c6 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -1787,13 +1787,14 @@ class Products extends DolibarrApi
* @param string $barcode Barcode of element
* @param int $includestockdata Load also information about stock (slower)
* @param bool $includesubproducts Load information about subproducts
+ * @param bool $includeparentid Load also ID of parent product if product is a variant
* @return array|mixed Data without useless information
*
* @throws RestException 401
* @throws RestException 403
* @throws RestException 404
*/
- private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0, $includesubproducts = false)
+ private function _fetch($id, $ref = '', $ref_ext = '', $barcode = '', $includestockdata = 0, $includesubproducts = false, $includeparentid = false)
{
if (empty($id) && empty($ref) && empty($ref_ext) && empty($barcode)) {
throw new RestException(400, 'bad value for parameter id, ref, ref_ext or barcode');
@@ -1814,12 +1815,6 @@ class Products extends DolibarrApi
throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login);
}
- $prodcomb = new ProductCombination($this->db);
- $this->product->fk_product_parent = null;
- if (($fk_product_parent = $prodcomb->getFkProductParentByFkProductChild($this->product->id)) > 0) {
- $this->product->fk_product_parent = $fk_product_parent;
- }
-
if ($includestockdata) {
$this->product->load_stock();
@@ -1846,6 +1841,14 @@ class Products extends DolibarrApi
$this->product->sousprods = $childs;
}
+ if ($includeparentid) {
+ $prodcomb = new ProductCombination($this->db);
+ $this->product->fk_product_parent = null;
+ if (($fk_product_parent = $prodcomb->getFkProductParentByFkProductChild($this->product->id)) > 0) {
+ $this->product->fk_product_parent = $fk_product_parent;
+ }
+ }
+
return $this->_cleanObjectDatas($this->product);
}
}
From 35c0bc81e2855f6fe5c22fcd9e0ecce8c38ff755 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 13:21:10 +0200
Subject: [PATCH 023/318] Update api_products.class.php
---
htdocs/product/class/api_products.class.php | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index 9721cd4a3c6..bd0270162cb 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -1786,8 +1786,8 @@ class Products extends DolibarrApi
* @param string $ref_ext Ref ext of element
* @param string $barcode Barcode of element
* @param int $includestockdata Load also information about stock (slower)
- * @param bool $includesubproducts Load information about subproducts
- * @param bool $includeparentid Load also ID of parent product if product is a variant
+ * @param bool $includesubproducts Load information about subproducts (if product is a virtual product)
+ * @param bool $includeparentid Load also ID of parent product (if product is a variant of a parent product)
* @return array|mixed Data without useless information
*
* @throws RestException 401
From d743cb6ac25dc6cf7fb4103c28cdb1ee6a147008 Mon Sep 17 00:00:00 2001
From: stickler-ci
Date: Fri, 4 Sep 2020 11:22:22 +0000
Subject: [PATCH 024/318] Fixing style errors.
---
htdocs/product/class/api_products.class.php | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/htdocs/product/class/api_products.class.php b/htdocs/product/class/api_products.class.php
index bd0270162cb..4163357c78e 100644
--- a/htdocs/product/class/api_products.class.php
+++ b/htdocs/product/class/api_products.class.php
@@ -1848,7 +1848,7 @@ class Products extends DolibarrApi
$this->product->fk_product_parent = $fk_product_parent;
}
}
-
+
return $this->_cleanObjectDatas($this->product);
}
}
From 4383f1d00c0188f1eb53a2ae2a9183475e110400 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur
Date: Fri, 4 Sep 2020 13:50:22 +0200
Subject: [PATCH 025/318] 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 026/318] 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 027/318] 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 028/318] 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 029/318] 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 030/318] 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 ccff18e2a564424d32ec921f3a183c942c86858e Mon Sep 17 00:00:00 2001
From: kamel
Date: Tue, 8 Sep 2020 14:48:50 +0200
Subject: [PATCH 031/318] NEW : Email configuration - Allow auto signed
certificat when ssl activated
---
htdocs/admin/mails.php | 37 ++++++++++++++++++++--
htdocs/admin/mails_emailing.php | 40 ++++++++++++++++++++++--
htdocs/core/class/CMailFile.class.php | 14 +++++++++
htdocs/core/class/smtps.class.php | 44 ++++++++++++++++++++++++---
htdocs/langs/en_US/admin.lang | 1 +
htdocs/langs/fr_FR/admin.lang | 1 +
6 files changed, 127 insertions(+), 10 deletions(-)
diff --git a/htdocs/admin/mails.php b/htdocs/admin/mails.php
index 476d782368e..c8c017c476e 100644
--- a/htdocs/admin/mails.php
+++ b/htdocs/admin/mails.php
@@ -77,6 +77,7 @@ if ($action == 'update' && empty($_POST["cancel"]))
dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW", GETPOST("MAIN_MAIL_SMTPS_PW", 'none'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS", GETPOST("MAIN_MAIL_EMAIL_TLS", 'int'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS", GETPOST("MAIN_MAIL_EMAIL_STARTTLS", 'int'), 'chaine', 0, '', $conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED", 'int'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_ENABLED", GETPOST("MAIN_MAIL_EMAIL_DKIM_ENABLED", 'int'), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_DKIM_DOMAIN", GETPOST("MAIN_MAIL_EMAIL_DKIM_DOMAIN", 'alphanohtml'), 'chaine', 0, '', $conf->entity);
@@ -156,6 +157,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").prop("disabled", true);
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
@@ -187,6 +190,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED.');
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val(0);
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").prop("disabled", true);
@@ -211,6 +216,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS.');
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").removeAttr("disabled");
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED.');
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").val('.$conf->global->MAIN_MAIL_EMAIL_DKIM_ENABLED.');
jQuery("#MAIN_MAIL_EMAIL_DKIM_ENABLED").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_DKIM_DOMAIN").removeAttr("disabled");
@@ -233,12 +240,16 @@ if ($action == 'edit')
initfields();
});
jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
- if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
+ if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val(0);
+ else
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
});
jQuery("#MAIN_MAIL_EMAIL_STARTTLS").change(function() {
- if (jQuery("#MAIN_MAIL_EMAIL_TLS").val() == 1)
+ if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS").val() == 1)
jQuery("#MAIN_MAIL_EMAIL_TLS").val(0);
+ else
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").val(0);
});
})';
print ''."\n";
@@ -408,6 +419,17 @@ if ($action == 'edit')
} else print yn(0).' ('.$langs->trans("NotSupported").')';
print ' | ';
+ // SMTP_ALLOW_SELF_SIGNED
+ print '| '.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").' | ';
+ if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer'))))
+ {
+ if (function_exists('openssl_open'))
+ {
+ print $form->selectyesno('MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED', (!empty($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED) ? $conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED : 0), 1);
+ } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
+ } else print yn(0).' ('.$langs->trans("NotSupported").')';
+ print ' | ';
+
// DKIM
print '| '.$langs->trans("MAIN_MAIL_EMAIL_DKIM_ENABLED").' | ';
if (!empty($conf->use_javascript_ajax) || (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('swiftmailer'))))
@@ -561,6 +583,17 @@ if ($action == 'edit')
} else print ''.yn(0).' ('.$langs->trans("NotSupported").')';
print ' | ';
+ // SMTP_ALLOW_SELF_SIGNED
+ print '| '.$langs->trans("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED").' | ';
+ if (isset($conf->global->MAIN_MAIL_SENDMODE) && in_array($conf->global->MAIN_MAIL_SENDMODE, array('smtps', 'swiftmailer')))
+ {
+ if (function_exists('openssl_open'))
+ {
+ print yn($conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED);
+ } else print yn(0).' ('.$langs->trans("YourPHPDoesNotHaveSSLSupport").')';
+ } else print ''.yn(0).' ('.$langs->trans("NotSupported").')';
+ print ' | ';
+
if ($conf->global->MAIN_MAIL_SENDMODE == 'swiftmailer')
{
diff --git a/htdocs/admin/mails_emailing.php b/htdocs/admin/mails_emailing.php
index f78ef0277bb..7e6f9acae93 100644
--- a/htdocs/admin/mails_emailing.php
+++ b/htdocs/admin/mails_emailing.php
@@ -68,6 +68,7 @@ if ($action == 'update' && empty($_POST["cancel"]))
dolibarr_set_const($db, "MAIN_MAIL_SMTPS_PW_EMAILING", GETPOST("MAIN_MAIL_SMTPS_PW_EMAILING"), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_TLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_TLS_EMAILING"), 'chaine', 0, '', $conf->entity);
dolibarr_set_const($db, "MAIN_MAIL_EMAIL_STARTTLS_EMAILING", GETPOST("MAIN_MAIL_EMAIL_STARTTLS_EMAILING"), 'chaine', 0, '', $conf->entity);
+ dolibarr_set_const($db, "MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING", GETPOST("MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING"), 'chaine', 0, '', $conf->entity);
header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup");
exit;
@@ -147,6 +148,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").prop("disabled", true);
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").prop("disabled", true);
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").prop("disabled", true);
';
if ($linuxlike)
{
@@ -173,6 +176,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
@@ -187,6 +192,8 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_STARTTLS_EMAILING.');
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").removeAttr("disabled");
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val('.$conf->global->MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING.');
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_PORT_EMAILING").removeAttr("disabled");
jQuery("#MAIN_MAIL_SMTP_SERVER_EMAILING").show();
@@ -199,13 +206,17 @@ if ($action == 'edit')
jQuery("#MAIN_MAIL_SENDMODE_EMAILING").change(function() {
initfields();
});
- jQuery("#MAIN_MAIL_EMAIL_TLS").change(function() {
- if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
+ jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").change(function() {
+ if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val(0);
+ else
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
});
jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").change(function() {
- if (jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val() == 1)
+ if (jQuery("#MAIN_MAIL_EMAIL_STARTTLS_EMAILING").val() == 1)
jQuery("#MAIN_MAIL_EMAIL_TLS_EMAILING").val(0);
+ else
+ jQuery("#MAIN_MAIL_EMAIL_SMTP_ALLOW_SELF_SIGNED_EMAILING").val(0);
});
})';
print ''."\n";
@@ -359,6 +370,18 @@ if ($action == 'edit')
} else print yn(0).' ('.$langs->trans("NotSupported").')';
print ' |
';
+ // SMTP_ALLOW_SELF_SIGNED_EMAILING
+
+ print '