Jump to content
jcuenin

Pack Produit - ajouter un champ supplémentaire

Recommended Posts

Bonjour,

J'aimerais ajouter un champ "numéro de pièce" lors de l'ajout d'un produit dans un pack produit mais sa valeur n'est pas sauvegardée en base de donnée. Je ne trouves pas quelle fonction se charge de mettre à jour les données dans la bdd. Est-ce que vous pourriez m'aider?

Voici ce que j'ai fais pour le moment :

  • Ajout d'une nouvelle colonne "num_piece" dans la table "ps_pack"
  • Surcharge de la classe Pack.php avec le code ci-dessous
  • Surcharge du controlleur AdminProducts avec le code ci-dessous
  • Surcharge du template pack.tpl avec le code ci-dessous

 

Mon fichier Pack.php

class Pack extends PackCore
{
    public static function getItems($id_product, $id_lang)
    {
        if (!Pack::isFeatureActive()) {
            return array();
        }

        if (array_key_exists($id_product, self::$cachePackItems)) {
            return self::$cachePackItems[$id_product];
        }
        $result = Db::getInstance()->executeS('SELECT id_product_item, id_product_attribute_item, quantity, num_piece FROM `'._DB_PREFIX_.'pack` where id_product_pack = '.(int)$id_product);
        $array_result = array();
        foreach ($result as $row) {
            $p = new Product($row['id_product_item'], false, $id_lang);
            $p->loadStockData();
            $p->pack_quantity = $row['quantity'];
            
            $p->pack_num_piece = $row['num_piece'];
            
            $p->id_pack_product_attribute = (isset($row['id_product_attribute_item']) && $row['id_product_attribute_item'] ? $row['id_product_attribute_item'] : 0);
            if (isset($row['id_product_attribute_item']) && $row['id_product_attribute_item']) {
                $sql = 'SELECT agl.`name` AS group_name, al.`name` AS attribute_name
					FROM `'._DB_PREFIX_.'product_attribute` pa
					'.Shop::addSqlAssociation('product_attribute', 'pa').'
					LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = pa.`id_product_attribute`
					LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
					LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
					LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)Context::getContext()->language->id.')
					LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)Context::getContext()->language->id.')
					WHERE pa.`id_product_attribute` = '.$row['id_product_attribute_item'].'
					GROUP BY pa.`id_product_attribute`, ag.`id_attribute_group`
					ORDER BY pa.`id_product_attribute`';

                $combinations = Db::getInstance()->executeS($sql);
                foreach ($combinations as $k => $combination) {
                    $p->name .= ' '.$combination['group_name'].'-'.$combination['attribute_name'];
                }
            }
            $array_result[] = $p;
        }
        self::$cachePackItems[$id_product] = $array_result;
        return self::$cachePackItems[$id_product];
    }
    
    public static function getItemTable($id_product, $id_lang, $full = false)
    {
        if (!Pack::isFeatureActive()) {
            return array();
        }

        $context = Context::getContext();

        $sql = 'SELECT p.*, product_shop.*, pl.*, image_shop.`id_image` id_image, il.`legend`, cl.`name` AS category_default, a.quantity AS pack_quantity, a.num_piece AS num_piece, product_shop.`id_category_default`, a.id_product_pack, a.id_product_attribute_item
				FROM `'._DB_PREFIX_.'pack` a
				LEFT JOIN `'._DB_PREFIX_.'product` p ON p.id_product = a.id_product_item
				LEFT JOIN `'._DB_PREFIX_.'product_lang` pl
					ON p.id_product = pl.id_product
					AND pl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('pl').'
				LEFT JOIN `'._DB_PREFIX_.'image_shop` image_shop
					ON (image_shop.`id_product` = p.`id_product` AND image_shop.cover=1 AND image_shop.id_shop='.(int)$context->shop->id.')
				LEFT JOIN `'._DB_PREFIX_.'image_lang` il ON (image_shop.`id_image` = il.`id_image` AND il.`id_lang` = '.(int)$id_lang.')
				'.Shop::addSqlAssociation('product', 'p').'
				LEFT JOIN `'._DB_PREFIX_.'category_lang` cl
					ON product_shop.`id_category_default` = cl.`id_category`
					AND cl.`id_lang` = '.(int)$id_lang.Shop::addSqlRestrictionOnLang('cl').'
				WHERE product_shop.`id_shop` = '.(int)$context->shop->id.'
				AND a.`id_product_pack` = '.(int)$id_product.'
				GROUP BY product_shop.id_product'; /* ceryom - modif GROUP BY a.id_product_attribute_item par GROUP BY product_shop.id_product - 17112017 */

        $result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);

        foreach ($result as &$line) {
            if (Combination::isFeatureActive() && isset($line['id_product_attribute_item']) && $line['id_product_attribute_item']) {
                $line['cache_default_attribute'] = $line['id_product_attribute'] = $line['id_product_attribute_item'];

                $sql = 'SELECT agl.`name` AS group_name, al.`name` AS attribute_name,  pai.`id_image` AS id_product_attribute_image
				FROM `'._DB_PREFIX_.'product_attribute` pa
				'.Shop::addSqlAssociation('product_attribute', 'pa').'
				LEFT JOIN `'._DB_PREFIX_.'product_attribute_combination` pac ON pac.`id_product_attribute` = '.$line['id_product_attribute_item'].'
				LEFT JOIN `'._DB_PREFIX_.'attribute` a ON a.`id_attribute` = pac.`id_attribute`
				LEFT JOIN `'._DB_PREFIX_.'attribute_group` ag ON ag.`id_attribute_group` = a.`id_attribute_group`
				LEFT JOIN `'._DB_PREFIX_.'attribute_lang` al ON (a.`id_attribute` = al.`id_attribute` AND al.`id_lang` = '.(int)Context::getContext()->language->id.')
				LEFT JOIN `'._DB_PREFIX_.'attribute_group_lang` agl ON (ag.`id_attribute_group` = agl.`id_attribute_group` AND agl.`id_lang` = '.(int)Context::getContext()->language->id.')
				LEFT JOIN `'._DB_PREFIX_.'product_attribute_image` pai ON ('.$line['id_product_attribute_item'].' = pai.`id_product_attribute`)
				WHERE pa.`id_product` = '.(int)$line['id_product'].' AND pa.`id_product_attribute` = '.$line['id_product_attribute_item'].'
				GROUP BY pa.`id_product_attribute`, ag.`id_attribute_group`
				ORDER BY pa.`id_product_attribute`';

                $attr_name = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);

                if (isset($attr_name[0]['id_product_attribute_image']) && $attr_name[0]['id_product_attribute_image']) {
                    $line['id_image'] = $attr_name[0]['id_product_attribute_image'];
                }
                $line['name'] .= "\n";
                foreach ($attr_name as $value) {
                    $line['name'] .= ' '.$value['group_name'].'-'.$value['attribute_name'];
                }
            }
            $line = Product::getTaxesInformations($line);
        }

        if (!$full) {
            return $result;
        }

        $array_result = array();
        foreach ($result as $prow) {
            if (!Pack::isPack($prow['id_product'])) {
                $prow['id_product_attribute'] = (int)$prow['id_product_attribute_item'];
                $array_result[] = Product::getProductProperties($id_lang, $prow);
            }
        }
        return $array_result;
    }
    

    public static function addItem($id_product, $id_item, $qty, $num_piece, $id_attribute_item = 0)
    {
        $id_attribute_item = (int)$id_attribute_item ? (int)$id_attribute_item : Product::getDefaultAttribute((int)$id_item);
        return Db::getInstance()->update('product', array('cache_is_pack' => 1), 'id_product = '.(int)$id_product) &&
            Db::getInstance()->insert('pack', array(
                'id_product_pack' => (int)$id_product,
                'id_product_item' => (int)$id_item,
                'id_product_attribute_item' => (int)$id_attribute_item,
                'quantity' => (int)$qty,
                'num_piece' => (int)$num_piece
                ))
            && Configuration::updateGlobalValue('PS_PACK_FEATURE_ACTIVE', '1');
    }
    
        public static function duplicate($id_product_old, $id_product_new)
    {
        Db::getInstance()->execute('INSERT INTO `'._DB_PREFIX_.'pack` (`id_product_pack`, `id_product_item`, `id_product_attribute_item`, `quantity`, `num_piece`)
		(SELECT '.(int)$id_product_new.', `id_product_item`, `id_product_attribute_item`, `quantity`, `num_piece` FROM `'._DB_PREFIX_.'pack` WHERE `id_product_pack` = '.(int)$id_product_old.')');

        // If return query result, a non-pack product will return false
        return true;
    }
    
}

Mon fichier AdminProductsController.php


class AdminProductsController extends AdminProductsControllerCore
{
    
    protected function initPack(Product $product)
	{
		$this->tpl_form_vars['is_pack'] = ($product->id && Pack::isPack($product->id)) || Tools::getValue('type_product') == Product::PTYPE_PACK;
		$product->packItems = Pack::getItems($product->id, $this->context->language->id);

		$input_pack_items = '';
		if (Tools::getValue('inputPackItems'))
			$input_pack_items = Tools::getValue('inputPackItems');
		else
			foreach ($product->packItems as $pack_item)
				$input_pack_items .= $pack_item->pack_quantity.'x'.$pack_item->id.'-';
		$this->tpl_form_vars['input_pack_items'] = $input_pack_items;

		$input_namepack_items = '';
		if (Tools::getValue('namePackItems'))
			$input_namepack_items = Tools::getValue('namePackItems');
		else
			foreach ($product->packItems as $pack_item)
				$input_namepack_items .= $pack_item->pack_quantity.' x '.$pack_item->name.'¤';
		$this->tpl_form_vars['input_namepack_items'] = $input_namepack_items;
	}
        
    public function updatePackItems($product)
	{
		Pack::deleteItems($product->id);
		// lines format: QTY x ID-QTY x ID
		if (Tools::getValue('type_product') == Product::PTYPE_PACK)
		{
			$product->setDefaultAttribute(0);//reset cache_default_attribute
			$items = Tools::getValue('inputPackItems');
			$lines = array_unique(explode('-', $items));

			// lines is an array of string with format : QTYxIDxID_PRODUCT_ATTRIBUTE
			if (count($lines))
				foreach ($lines as $line)
					if (!empty($line))
					{
						$item_id_attribute = 0;
						count($array = explode('x', $line)) == 3 ? list($qty, $item_id, $item_id_attribute) = $array : list($qty, $item_id) = $array;
						if ($qty > 0 && isset($item_id))
						{
							if (Pack::isPack((int)$item_id))
								$this->errors[] = Tools::displayError('You can\'t add product packs into a pack');
							elseif (!Pack::addItem((int)$product->id, (int)$item_id, (int)$qty, (int)$num_piece, (int)$item_id_attribute))
								$this->errors[] = Tools::displayError('An error occurred while attempting to add products to the pack.');
						}
					}
		}
	}
        
        /**
	 * Get an array of pack items for display from the product object if specified, else from POST/GET values
	 *
	 * @param Product $product
	 * @return array of pack items
	 */
	public function getPackItems($product = null)
	{
		$pack_items = array();

		if (!$product)
		{
			$names_input = Tools::getValue('namePackItems');
			$ids_input = Tools::getValue('inputPackItems');
			if (!$names_input || !$ids_input)
				return array();
			// ids is an array of string with format : QTYxID
			$ids = array_unique(explode('-', $ids_input));
			$names = array_unique(explode('¤', $names_input));

			if (!empty($ids))
			{
				$length = count($ids);
				for ($i = 0; $i < $length; $i++)
				{
					if (!empty($ids[$i]) && !empty($names[$i]))
					{
						list($pack_items[$i]['pack_quantity'], $pack_items[$i]['id']) = explode('x', $ids[$i]);
						$exploded_name = explode('x', $names[$i]);
						$pack_items[$i]['name'] = $exploded_name[1];
					}
				}
			}
		}
		else
		{
			$i = 0;
			foreach ($product->packItems as $pack_item)
			{
				$pack_items[$i]['id'] = $pack_item->id;
				$pack_items[$i]['pack_quantity'] = $pack_item->pack_quantity;
                                
                                $pack_items[$i]['pack_num_piece'] = $pack_item->pack_num_piece;
                                
				$pack_items[$i]['name']	= $pack_item->name;
				$pack_items[$i]['reference'] = $pack_item->reference;
				$pack_items[$i]['id_product_attribute'] = isset($pack_item->id_pack_product_attribute) && $pack_item->id_pack_product_attribute ? $pack_item->id_pack_product_attribute : 0;
				$cover = $pack_item->id_pack_product_attribute ? Product::getCombinationImageById($pack_item->id_pack_product_attribute, Context::getContext()->language->id) : Product::getCover($pack_item->id);
				$pack_items[$i]['image'] = Context::getContext()->link->getImageLink($pack_item->link_rewrite, $cover['id_image'], 'home_default');
				// @todo: don't rely on 'home_default'
				//$path_to_image = _PS_IMG_DIR_.'p/'.Image::getImgFolderStatic($cover['id_image']).(int)$cover['id_image'].'.jpg';
				//$pack_items[$i]['image'] = ImageManager::thumbnail($path_to_image, 'pack_mini_'.$pack_item->id.'_'.$this->context->shop->id.'.jpg', 120);
				$i++;
			}
		}
		return $pack_items;
	}

	public function initFormPack($product)
	{
		$data = $this->createTemplate($this->tpl_form);

		// If pack items have been submitted, we want to display them instead of the actuel content of the pack
		// in database. In case of a submit error, the posted data is not lost and can be sent again.
		if (Tools::getValue('namePackItems'))
		{
			$input_pack_items = Tools::getValue('inputPackItems');
			$input_namepack_items = Tools::getValue('namePackItems');
			$pack_items = $this->getPackItems();
		}
		else
		{
			$product->packItems = Pack::getItems($product->id, $this->context->language->id);
			$pack_items = $this->getPackItems($product);
			$input_namepack_items = '';
			$input_pack_items = '';
			foreach ($pack_items as $pack_item)
			{
				$input_pack_items .= $pack_item['pack_quantity'].'x'.$pack_item['id'].'x'.$pack_item['id_product_attribute'].'-';
				$input_namepack_items .= $pack_item['pack_quantity'].' x '.$pack_item['name'].'¤';
			}
		}

		$data->assign(array(
			'input_pack_items' => $input_pack_items,
			'input_namepack_items' => $input_namepack_items,
			'pack_items' => $pack_items,
			'product_type' => (int)Tools::getValue('type_product', $product->getType())
		));

		$this->tpl_form_vars['custom_form'] = $data->fetch();
	}
    
}

Mon fichier pack.tpl

<input type="hidden" name="submitted_tabs[]" value="Pack" />
<hr />
<div class="form-group listOfPack">
	<label class="control-label col-lg-3 product_description">
		{l s='List of products of this pack'}
	</label>
	<div class="col-lg-9">
		<p class="alert alert-warning pack-empty-warning" {if $pack_items|@count != 0}style="display:none"{/if}>{l s='This pack is empty. You must add at least one product item.'}</p>
		<ul id="divPackItems" class="list-unstyled">
			{foreach $pack_items as $pack_item}
				<li class="product-pack-item media-product-pack" data-product-name="{$curPackItemName}" data-product-qty="{$pack_item.pack_quantity}" data-product-id="{$pack_item.id}" data-product-id-attribute="{$pack_item.id_product_attribute}">
					<img class="media-product-pack-img" src="{$pack_item.image}"/>
					<span class="media-product-pack-title">{$pack_item.name}</span>
					<span class="media-product-pack-ref">REF: {$pack_item.reference}</span>
					<span class="media-product-pack-quantity"><span class="text-muted">x</span>{$pack_item.pack_quantity}</span>
                                        <span class="media-product-pack-num-piece">Numéro pièce : {$pack_item.pack_num_piece}</span>
					<button type="button" class="btn btn-default delPackItem media-product-pack-action" data-delete="{$pack_item.id}" data-delete-attr="{$pack_item.id_product_attribute}"><i class="icon-trash"></i></button>
				</li>
			{/foreach}
		</ul>
	</div>
</div>
<div class="form-group addProductToPack">
	<label class="control-label col-lg-3" for="curPackItemName">
		<span class="label-tooltip" data-toggle="tooltip" title="{l s='Start by typing the first letters of the product name, then select the product from the drop-down list.'}">
			{l s='Add product in your pack'}
		</span>
	</label>
	<div class="col-lg-9">
		<div class="row">
			<div class="col-lg-6">
				<input type="text" id="curPackItemName" name="curPackItemName" class="form-control" />
			</div>
			<div class="col-lg-2">
				<div class="input-group">
					<span class="input-group-addon">&times;</span>
					<input type="number" name="curPackItemQty" id="curPackItemQty" class="form-control" min="1" value="1"/>
				</div>
			</div>
                    
                        <div class="col-lg-2">
				<div class="input-group">
					<input type="number" placeholder="Numéro pièce" name="curPackItemNum" id="curPackItemNum" class="form-control" min="1" />
				</div>
			</div>
                    
                    
			<div class="col-lg-2">
				<button type="button" id="add_pack_item" class="btn btn-default">
					<i class="icon-plus-sign-alt"></i> {l s='Add this product'}
				</button>
			</div>
		</div>
	</div>
</div>

<input type="hidden" name="inputPackItems" id="inputPackItems" value="{$input_pack_items}" placeholder="inputs"/>
<input type="hidden" name="namePackItems" id="namePackItems" value="{$input_namepack_items}" placeholder="name"/>

Merci par avance pour vos réponses et bonne journée,

Bien à vous,

Julien

Share this post


Link to post
Share on other sites

Bah votre code à l'air correct et c'est cette ligne-là qui insère le pack en bdd:

elseif (!Pack::addItem((int)$product->id, (int)$item_id, (int)$qty, (int)$num_piece, (int)$item_id_attribute))
								$this->errors[] = Tools::displayError('An error occurred while attempting to add products to the pack.');

Aucune erreur en affichage, ni dans les logs ?

Quelle est la structure de votre table ps_pack, parce que le pb doit venir de là...

Edited by Eolia (see edit history)

Share this post


Link to post
Share on other sites

Hum, non... votre problème se situe ici car $num_pièce n'est pas défini:

$product->setDefaultAttribute(0);//reset cache_default_attribute
			$items = Tools::getValue('inputPackItems');
			$lines = array_unique(explode('-', $items));

			// lines is an array of string with format : QTYxIDxID_PRODUCT_ATTRIBUTE
			if (count($lines))
				foreach ($lines as $line)
					if (!empty($line))
					{
						$item_id_attribute = 0;
						count($array = explode('x', $line)) == 3 ? list($qty, $item_id, $item_id_attribute) = $array : list($qty, $item_id) = $array;
						if ($qty > 0 && isset($item_id))
						{
							if (Pack::isPack((int)$item_id))
								$this->errors[] = Tools::displayError('You can\'t add product packs into a pack');
							elseif (!Pack::addItem((int)$product->id, (int)$item_id, (int)$qty, (int)$num_piece, (int)$item_id_attribute))
								$this->errors[] = Tools::displayError('An error occurred while attempting to add products to the pack.');
						}
					}

Les variables $item_id, $qty et $item_id_attribute sont obtenues à partir d'un explode de la ligne comme expliqué dans le commentaire: // lines is an array of string with format : QTYxIDxID_PRODUCT_ATTRIBUTE

Ceux-ci étant définis ici:


			foreach ($pack_items as $pack_item)
			{
				$input_pack_items .= $pack_item['pack_quantity'].'x'.$pack_item['id'].'x'.$pack_item['id_product_attribute'].'-';
				$input_namepack_items .= $pack_item['pack_quantity'].' x '.$pack_item['name'].'¤';
			}

Vous devez donc rajouter votre valeur dans le string $input_pack_item...

Share this post


Link to post
Share on other sites

Merci pour votre aide, en effet je n'avais pas remarqué cette partie. A priori cela semble fonctionner maintenant.

Il a fallu également modifier des éléments dans le fichier js/admin/product.js, est-ce qu'il est possible de le surcharger également? ci-dessous la liste des modifications.

 

A modifier dans AdminProductsController.php

public function getPackItems($product = null)
	{
		$pack_items = array();

		if (!$product)
		{
			$names_input = Tools::getValue('namePackItems');
			$ids_input = Tools::getValue('inputPackItems');
			if (!$names_input || !$ids_input)
				return array();
			// ids is an array of string with format : QTYxID
			$ids = array_unique(explode('-', $ids_input));
			$names = array_unique(explode('¤', $names_input));

			if (!empty($ids))
			{
				$length = count($ids);
				for ($i = 0; $i < $length; $i++)
				{
					if (!empty($ids[$i]) && !empty($names[$i]))
					{
						list($pack_items[$i]['pack_quantity'], $pack_items[$i]['id']) = explode('x', $ids[$i]);
						$exploded_name = explode('x', $names[$i]);
						$pack_items[$i]['name'] = $exploded_name[1];
					}
				}
			}
		}
		else
		{
			$i = 0;
			foreach ($product->packItems as $pack_item)
			{
				$pack_items[$i]['id'] = $pack_item->id;
				$pack_items[$i]['pack_quantity'] = $pack_item->pack_quantity;
                                
                                $pack_items[$i]['num_piece'] = $pack_item->num_piece;
                                
				$pack_items[$i]['name']	= $pack_item->name;
				$pack_items[$i]['reference'] = $pack_item->reference;
				$pack_items[$i]['id_product_attribute'] = isset($pack_item->id_pack_product_attribute) && $pack_item->id_pack_product_attribute ? $pack_item->id_pack_product_attribute : 0;
				$cover = $pack_item->id_pack_product_attribute ? Product::getCombinationImageById($pack_item->id_pack_product_attribute, Context::getContext()->language->id) : Product::getCover($pack_item->id);
				$pack_items[$i]['image'] = Context::getContext()->link->getImageLink($pack_item->link_rewrite, $cover['id_image'], 'home_default');
				// @todo: don't rely on 'home_default'
				//$path_to_image = _PS_IMG_DIR_.'p/'.Image::getImgFolderStatic($cover['id_image']).(int)$cover['id_image'].'.jpg';
				//$pack_items[$i]['image'] = ImageManager::thumbnail($path_to_image, 'pack_mini_'.$pack_item->id.'_'.$this->context->shop->id.'.jpg', 120);
				$i++;
			}
		}
		return $pack_items;
	}

	public function initFormPack($product)
	{
		$data = $this->createTemplate($this->tpl_form);

		// If pack items have been submitted, we want to display them instead of the actuel content of the pack
		// in database. In case of a submit error, the posted data is not lost and can be sent again.
		if (Tools::getValue('namePackItems'))
		{
			$input_pack_items = Tools::getValue('inputPackItems');
			$input_namepack_items = Tools::getValue('namePackItems');
			$pack_items = $this->getPackItems();
		}
		else
		{
			$product->packItems = Pack::getItems($product->id, $this->context->language->id);
			$pack_items = $this->getPackItems($product);
			$input_namepack_items = '';
			$input_pack_items = '';
			foreach ($pack_items as $pack_item)
			{
				$input_pack_items .= $pack_item['pack_quantity'].'x'.$pack_item['id'].'x'.$pack_item['id_product_attribute'].'x'.$pack_item['num_piece'].'-';
				$input_namepack_items .= $pack_item['pack_quantity'].' x '.$pack_item['name'].'¤';
			}
		}

		$data->assign(array(
			'input_pack_items' => $input_pack_items,
			'input_namepack_items' => $input_namepack_items,
			'pack_items' => $pack_items,
			'product_type' => (int)Tools::getValue('type_product', $product->getType())
		));

		$this->tpl_form_vars['custom_form'] = $data->fetch();
	}

A modifier dans js/admin/product.js,

function addPackItem() {

			if (selectedProduct) {
				selectedProduct.qty = $('#curPackItemQty').val();
                                
                                selectedProduct.num_piece = $('#curPackItemNumPiece').val(); // ligne ajoutée
                                
				if (selectedProduct.id == '' || selectedProduct.name == '' && $('#curPackItemQty').valid()) {
					error_modal(error_heading_msg, msg_select_one);
					return false;
				} else if (selectedProduct.qty == '' || !$('#curPackItemQty').valid() || isNaN($('#curPackItemQty').val()) ) {
					error_modal(error_heading_msg, msg_set_quantity);
					return false;
				}

				if (typeof selectedProduct.id_product_attribute === 'undefined')
					selectedProduct.id_product_attribute = 0;

				var divContent = $('#divPackItems').html();
				divContent += '<li class="product-pack-item media-product-pack" data-product-name="' + selectedProduct.name + '" data-product-qty="' + selectedProduct.qty + '" data-product-id="' + selectedProduct.id + '" data-product-id-attribute="' + selectedProduct.id_product_attribute + '">';
				divContent += '<img class="media-product-pack-img" src="' + selectedProduct.image +'"/>';
				divContent += '<span class="media-product-pack-title">' + selectedProduct.name + '</span>';
				divContent += '<span class="media-product-pack-ref">REF: ' + selectedProduct.ref + '</span>';
				divContent += '<span class="media-product-pack-quantity"><span class="text-muted">x</span> ' + selectedProduct.qty + '</span>';
				divContent += '<button type="button" class="btn btn-default delPackItem media-product-pack-action" data-delete="' + selectedProduct.id + '" data-delete-attr="' + selectedProduct.id_product_attribute + '"><i class="icon-trash"></i></button>';
				divContent += '</li>';

				// QTYxID-QTYxID
				// @todo : it should be better to create input for each items and each qty
				// instead of only one separated by x, - and ¤
				var line = selectedProduct.qty + 'x' + selectedProduct.id + 'x' + selectedProduct.id_product_attribute + 'x' + selectedProduct.num_piece; // ajout num_piece
				var lineDisplay = selectedProduct.qty + 'x ' + selectedProduct.name;

				$('#divPackItems').html(divContent);
				$('#inputPackItems').val($('#inputPackItems').val() + line  + '-');
				$('#namePackItems').val($('#namePackItems').val() + lineDisplay + '¤');

				$('.delPackItem').on('click', function(e){
					e.preventDefault();
					e.stopPropagation();
					delPackItem($(this).data('delete'), $(this).data('delete-attr'));
				})
				selectedProduct = null;
				$('#curPackItemName').select2("val", "");
				$('.pack-empty-warning').hide();
			} else {
				error_modal(error_heading_msg, msg_select_one);
				return false;
			}
		}

 

Share this post


Link to post
Share on other sites

Il n'y a malheureusement pas d'override en js chez Prestashop.

Un conseil, copier cette fonction dans un fichier séparé et déposez-le dans le répertoire js pour pouvoir restaurer rapidement celle-ci en cas de mise à jour

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More