Jump to content

[RESOLU] Choix ajout au panier différent selon catégorie


123julien

Recommended Posts

Bonjour à tous,

Je me permets de revenir vers vous avec une nouvelle question.
Je ne pense pas que cela soit bien compliqué mais ma recherche sur le forum n'a pas été très efficace.

Je souhaiterai en fait simplement proposé en fonction de la catégorie de produits deux listes de quantités pour la mise au panier.

J'ai pour l'instant ce morceau de code sur ma page product.tpl

            

quantity == 0) || $virtual} style="display:none;"{/if}>
{l s='Quantity :'}

3
6
9
12
18
24
30
36
42
48
54
60




Mais j'aimerai que pour la catégorie 17 la liste soit uniquement 1,2,3,4,5 donc je suppose qu'il faut jouer avec un {if} mais je n'arrive pas à trouver quelle serait la bonne solution.

D'avance merci pour votre aide,

Julien

Link to comment
Share on other sites

Ok super merci beaucoup.
Tu m'as mis sur la voie.

Voici le code final

{if $category->id_category EQ 18}

1
2
3
4
5

               {elseif $category->id_category EQ 19}

1
2
3
4
5

               {elseif $category->id_category EQ 21}

1
2
3
4
5

               {else}

3
6
9
12
18
24
30
36
42
48
54
60

               {/if}



Encore merci

Ju

Link to comment
Share on other sites

  • 2 weeks later...

Salut julien,
j'ai bien une idée qui ma prise 30 mn ... ;)

Dans cart.php modifier :

if ($qty == 0)
       $errors[] = Tools::displayError('null quantity');
   elseif (!$idProduct)
       $errors[] = Tools::displayError('product not found');
   else
   {
       $producToAdd = new Product(intval($idProduct), false, intval($cookie->id_lang));
       if ((!$producToAdd->id OR !$producToAdd->active) AND !$delete)
           $errors[] = Tools::displayError('product is no longer available');
       else
       {

           /* Check the quantity availability */
           if ($idProductAttribute AND is_numeric($idProductAttribute))
           {
               if (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty(intval($idProductAttribute), intval($qty)))
                   $errors[] = Tools::displayError('product is no longer available');
           }



par ....

if ($qty == 0)
       $errors[] = Tools::displayError('null quantity');
   elseif (!$idProduct)
       $errors[] = Tools::displayError('product not found');
   else
   {
       $producToAdd = new Product(intval($idProduct), false, intval($cookie->id_lang));
       if ((!$producToAdd->id OR !$producToAdd->active) AND !$delete)
           $errors[] = Tools::displayError('product is no longer available');
       else
       {

           //**** TEST/HELP 30/12/2009 : ajout par lot
           $catId=$producToAdd->id_category_default;
           if($catId!=18 AND $catId!=19 AND $catId!=21)
           {
               $addQtyArray = array(3, 6, 9, 12, 18, 24, 30, 36, 42, 48, 54, 60);
               $row=$cart->containsProduct(intval($idProduct), intval($idProductAttribute), $customizationId);
               $currentQty=$row['quantity'];
               for ($index = 0; $index < count($addQtyArray); $index++) 
                 {  
                   if($currentQty==$addQtyArray[$index])
                   {
                           if(Tools::getValue('op', 'up')=='up')
                           {
                               if($index != count($addQtyArray)-1)
                               {
                                   $qty=$addQtyArray[$index+1]-$addQtyArray[$index];
                               }
                               else
                               {
                                   $errors[] = Tools::displayError('you already have the maximum quantity available for this product');
                               }                            
                           }
                           else
                           {
                               $qty=$addQtyArray[$index]-$addQtyArray[$index-1];
                           }
                       break;
                   }
                 }
           }
           //**** fin modif


           /* Check the quantity availability */
           if ($idProductAttribute AND is_numeric($idProductAttribute))
           {
               if (!$delete AND !$producToAdd->isAvailableWhenOutOfStock($producToAdd->out_of_stock) AND !Attribute::checkAttributeQty(intval($idProductAttribute), intval($qty)))
                   $errors[] = Tools::displayError('product is no longer available');
           }



Voila ...

Pierre.

Link to comment
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...