Heray-Was-Here
Server : Apache
System : Linux mail.lomejor.cr 6.8.0-1059-azure #65~22.04.1-Ubuntu SMP Thu May 28 16:59:19 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.2.31
Disable Function : NONE
Directory :  /var/www/erp/htdocs/variants/class/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/erp/htdocs/variants/class/ProductCombination2ValuePair.class.php
<?php
/* Copyright (C) 2016	Marcos García	<marcosgdf@gmail.com>
 * Copyright (C) 2022   Open-Dsi		<support@open-dsi.fr>
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
 */

/**
 * Class ProductCombination2ValuePair
 * Used to represent the relation between a product combination, a product attribute and a product attribute value
 */
class ProductCombination2ValuePair
{
	/**
	 * Database handler
	 * @var DoliDB
	 */
	private $db;

	/**
	 * Combination 2 value pair id
	 * @var int
	 */
	public $id;

	/**
	 * Product combination id
	 * @var int
	 */
	public $fk_prod_combination;

	/**
	 * Product attribute id
	 * @var int
	 */
	public $fk_prod_attr;

	/**
	 * Product attribute value id
	 * @var int
	 */
	public $fk_prod_attr_val;

	/**
	 * Constructor
	 *
	 * @param   DoliDB $db     Database handler
	 */
	public function __construct(DoliDB $db)
	{
		$this->db = $db;
	}

	/**
	 * Translates this class to a human-readable string
	 *
	 * @return string
	 */
	public function __toString()
	{
		require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductAttributeValue.class.php';
		require_once DOL_DOCUMENT_ROOT . '/variants/class/ProductAttribute.class.php';

		$prodattr = new ProductAttribute($this->db);
		$prodattrval = new ProductAttributeValue($this->db);

		$prodattr->fetch($this->fk_prod_attr);
		$prodattrval->fetch($this->fk_prod_attr_val);

		return $prodattr->label . ': ' . $prodattrval->value;
	}

	/**
	 * Creates a product combination 2 value pair
	 * @return int <0 KO, >0 OK
	 */
	public function create()
	{
		$sql = "INSERT INTO " . MAIN_DB_PREFIX . "product_attribute_combination2val
		(fk_prod_combination, fk_prod_attr, fk_prod_attr_val)
		VALUES(" . (int) $this->fk_prod_combination . ", " . (int) $this->fk_prod_attr . ", " . (int) $this->fk_prod_attr_val . ")";

		$query = $this->db->query($sql);

		if ($query) {
			$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . 'product_attribute_combination2val');

			return 1;
		}

		return -1;
	}

	/**
	 * Retrieves a product combination 2 value pair from its rowid
	 *
	 * @param int $fk_combination Fk combination to search
	 * @return int|ProductCombination2ValuePair[] -1 if KO
	 */
	public function fetchByFkCombination($fk_combination)
	{
		$sql = "SELECT
        c.rowid,
        c2v.fk_prod_attr_val,
        c2v.fk_prod_attr,
        c2v.fk_prod_combination
        FROM " . MAIN_DB_PREFIX . "product_attribute c LEFT JOIN " . MAIN_DB_PREFIX . "product_attribute_combination2val c2v ON c.rowid = c2v.fk_prod_attr
        WHERE c2v.fk_prod_combination = " . (int) $fk_combination;

		$sql .= $this->db->order('c.position', 'asc');

		$query = $this->db->query($sql);

		if (!$query) {
			return -1;
		}

		$return = array();

		while ($obj = $this->db->fetch_object($query)) {
			$tmp = new ProductCombination2ValuePair($this->db);
			$tmp->fk_prod_attr_val = $obj->fk_prod_attr_val;
			$tmp->fk_prod_attr = $obj->fk_prod_attr;
			$tmp->fk_prod_combination = $obj->fk_prod_combination;
			$tmp->id = $obj->rowid;

			$return[] = $tmp;
		}

		return $return;
	}

	/**
	 * Deletes a product combination 2 value pair
	 *
	 * @param int $fk_combination Rowid of the combination
	 * @return int >0 OK <0 KO
	 */
	public function deleteByFkCombination($fk_combination)
	{
		$sql = "DELETE FROM " . MAIN_DB_PREFIX . "product_attribute_combination2val WHERE fk_prod_combination = " . (int) $fk_combination;

		if ($this->db->query($sql)) {
			return 1;
		}

		return -1;
	}
}

Hry