[Skip to main content](#vessel-content)

#   mettre a jour une table apres enregistrement d'un produit

##

- **[erickb](/forum/user/4069-erickb "View erickb's Profile")**
- [![erickb's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/4069-erickb "View erickb's Profile") Topic Author
- [ Offline](/forum/user/4069-erickb)

Less More

- Posts: 2697
- Thank you received: 74
-
-

7 years 2 months ago -  7 years 2 months ago [\#310340](#310340) by [erickb](/forum/user/4069-erickb "View erickb's Profile")  *[trigger ne marche pas](/forum/5-support-en-francais-french-support-/898182-mettre-a-jour-une-table-apres-enregistrement-dun-produit#310340 "-- HikaShop version -- : 4.2.1  Bonjour  j'ai cree un trigger qui marche parfaitement si je le fais sur une copie exacte de la table hikashop&#95;product&#95;category mais qui est sans effet sur la table elle meme et je ne comprend vraiment pas ce qui peut bloquer  quand mon champ hikashot&#95;product.product&#95;size&#95;values change je met a jour hikashop&#95;product&#95;category  si mon hikashop&#95;product.product&#95;size&#95;values = '41,42,46' je rentre 3 lignes dans hikashop&#95;product&#95;category (product&#95;id, category&#95;id) values (new.product&#95;id, 441); (product&#95;id, category&#95;id) values (new.product&#95;id, 442); (product&#95;id, category&#95;id) values (new.product&#95;id, 446);  pourquoi le trigger n'a aucun effet alors que tout marche ? merci pour l'aide")* was created by *[erickb](/forum/user/4069-erickb "View erickb's Profile")*

-- HikaShop version -- : 4.2.1

Bonjour

j'ai cree un trigger qui marche parfaitement si je le fais sur une copie exacte de la table hikashop_product_category mais qui est sans effet sur la table elle meme et je ne comprend vraiment pas ce qui peut bloquer

quand mon champ hikashot_product.product_size_values change je met a jour hikashop_product_category

si mon hikashop_product.product_size_values = '41,42,46'
je rentre 3 lignes dans hikashop_product_category
(product_id, category_id) values (new.product_id, 441);
(product_id, category_id) values (new.product_id, 442);
(product_id, category_id) values (new.product_id, 446);

Code:

CREATE TRIGGER trg_product_size AFTER UPDATE ON fr_hikashop_product FOR EACH ROW BEGIN DECLARE x INT; IF (new.product_size_values != OLD.product_size_values) THEN DELETE FROM fr_hikashop_product_category WHERE product_id = new.product_id AND category_id BETWEEN 441 AND 448; set x = 41 ; while x &lt; 49 do if LOCATE(x, new.product_size_values) &gt; 0 then INSERT IGNORE INTO fr_hikashop_product_category (product_id, category_id) values (new.product_id, CONCAT('4',x )); end if; set x=x+1; end while ; END IF; END //

pourquoi le trigger n'a aucun effet alors que tout marche ?
merci pour l'aide

Last edit: 7 years 2 months ago by [erickb](/forum/user/4069-erickb "View erickb's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vODk4MTgyLW1ldHRyZS1hLWpvdXItdW5lLXRhYmxlLWFwcmVzLWVucmVnaXN0cmVtZW50LWR1bi1wcm9kdWl0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[nicolas](/forum/user/63-nicolas "View nicolas's Profile")**
- [![nicolas's Avatar](https://www.hikashop.com/media/kunena/avatars/resized/size144/users/avatar63.png?1793428657)](/forum/user/63-nicolas "View nicolas's Profile")
- [ Away](/forum/user/63-nicolas)

Less More

- Posts: 86320
- Thank you received: 14276
-
-

7 years 2 months ago -  7 years 2 months ago [\#310347](#310347) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[mettre a jour une table apres enregistrement d'un produit](/forum/5-support-en-francais-french-support-/898182-mettre-a-jour-une-table-apres-enregistrement-dun-produit#310347 "-- HikaShop version -- : 4.2.1  Bonjour  j'ai cree un trigger qui marche parfaitement si je le fais sur une copie exacte de la table hikashop&#95;product&#95;category mais qui est sans effet sur la table elle meme et je ne comprend vraiment pas ce qui peut bloquer  quand mon champ hikashot&#95;product.product&#95;size&#95;values change je met a jour hikashop&#95;product&#95;category  si mon hikashop&#95;product.product&#95;size&#95;values = '41,42,46' je rentre 3 lignes dans hikashop&#95;product&#95;category (product&#95;id, category&#95;id) values (new.product&#95;id, 441); (product&#95;id, category&#95;id) values (new.product&#95;id, 442); (product&#95;id, category&#95;id) values (new.product&#95;id, 446);  pourquoi le trigger n'a aucun effet alors que tout marche ? merci pour l'aide")*

Bonjour,

Pour appeler une procédure stockée après l'enregistrement d'un produit, il vous faut utiliser un trigger MySQL:
[ stackoverflow.com/questions/44745097/mys...ting-new-row-in-tabl](https://stackoverflow.com/questions/44745097/mysql-how-to-dynamically-call-stored-procedures-when-inserting-new-row-in-tabl)
Mais bon, les procédures stockées associées à des triggers sont déconseillées d'après ce que je lis sur internet. Et je ne saurais vous aider sur le sujet. Je n'ai jamais fair de trigger MySQL de ma vie, donc vous en savez déjà plus que moi sur le sujet.

Je pense aussi que c'est possible de faire cela avec une action de masse:
[ monosnap.com/file/b4V3vUtgByP7syPE0GCMR2ThCkzUyx](https://monosnap.com/file/b4V3vUtgByP7syPE0GCMR2ThCkzUyx)
Sinon, il est je pense préférable de faire un petit plugin implémentant onAfterProductCreate et onAfterProductUpdate pour faire votre requête d'INSERT MySQL.

Last edit: 7 years 2 months ago by [nicolas](/forum/user/63-nicolas "View nicolas's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vODk4MTgyLW1ldHRyZS1hLWpvdXItdW5lLXRhYmxlLWFwcmVzLWVucmVnaXN0cmVtZW50LWR1bi1wcm9kdWl0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[erickb](/forum/user/4069-erickb "View erickb's Profile")**
- [![erickb's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/4069-erickb "View erickb's Profile") Topic Author
- [ Offline](/forum/user/4069-erickb)

Less More

- Posts: 2697
- Thank you received: 74
-
-

7 years 2 months ago -  7 years 2 months ago [\#310381](#310381) by [erickb](/forum/user/4069-erickb "View erickb's Profile")  Replied by *[erickb](/forum/user/4069-erickb "View erickb's Profile")* on topic *[mettre a jour une table apres enregistrement d'un produit](/forum/5-support-en-francais-french-support-/898182-mettre-a-jour-une-table-apres-enregistrement-dun-produit#310381 "-- HikaShop version -- : 4.2.1  Bonjour  j'ai cree un trigger qui marche parfaitement si je le fais sur une copie exacte de la table hikashop&#95;product&#95;category mais qui est sans effet sur la table elle meme et je ne comprend vraiment pas ce qui peut bloquer  quand mon champ hikashot&#95;product.product&#95;size&#95;values change je met a jour hikashop&#95;product&#95;category  si mon hikashop&#95;product.product&#95;size&#95;values = '41,42,46' je rentre 3 lignes dans hikashop&#95;product&#95;category (product&#95;id, category&#95;id) values (new.product&#95;id, 441); (product&#95;id, category&#95;id) values (new.product&#95;id, 442); (product&#95;id, category&#95;id) values (new.product&#95;id, 446);  pourquoi le trigger n'a aucun effet alors que tout marche ? merci pour l'aide")*

j'ai vais essayer un plugin

Last edit: 7 years 2 months ago by [erickb](/forum/user/4069-erickb "View erickb's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vODk4MTgyLW1ldHRyZS1hLWpvdXItdW5lLXRhYmxlLWFwcmVzLWVucmVnaXN0cmVtZW50LWR1bi1wcm9kdWl0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[erickb](/forum/user/4069-erickb "View erickb's Profile")**
- [![erickb's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/4069-erickb "View erickb's Profile") Topic Author
- [ Offline](/forum/user/4069-erickb)

Less More

- Posts: 2697
- Thank you received: 74
-
-

7 years 2 months ago -  7 years 2 months ago [\#310389](#310389) by [erickb](/forum/user/4069-erickb "View erickb's Profile")  Replied by *[erickb](/forum/user/4069-erickb "View erickb's Profile")* on topic *[mettre a jour une table apres enregistrement d'un produit](/forum/5-support-en-francais-french-support-/898182-mettre-a-jour-une-table-apres-enregistrement-dun-produit#310389 "-- HikaShop version -- : 4.2.1  Bonjour  j'ai cree un trigger qui marche parfaitement si je le fais sur une copie exacte de la table hikashop&#95;product&#95;category mais qui est sans effet sur la table elle meme et je ne comprend vraiment pas ce qui peut bloquer  quand mon champ hikashot&#95;product.product&#95;size&#95;values change je met a jour hikashop&#95;product&#95;category  si mon hikashop&#95;product.product&#95;size&#95;values = '41,42,46' je rentre 3 lignes dans hikashop&#95;product&#95;category (product&#95;id, category&#95;id) values (new.product&#95;id, 441); (product&#95;id, category&#95;id) values (new.product&#95;id, 442); (product&#95;id, category&#95;id) values (new.product&#95;id, 446);  pourquoi le trigger n'a aucun effet alors que tout marche ? merci pour l'aide")*

mon plugin n'a absolument aucun effet alors qu'il marche si je met a jour n'importe quoi d'autre, et si je récupère les requetes générées et les colle dans phpmyadmin tout marche
Code:

class plgHikashopSynchro extends JPlugin { function __construct(&amp;$subject, $config) { parent::__construct($subject, $config); } function onAfterProductUpdate(&amp;$product) { $this-&gt;_productSynchro($product); } function onAfterProductCreate(&amp;$product) { $this-&gt;_productSynchro($product); } function _productSynchro(&amp;$product) { $s = ''; $pid = $product-&gt;product_id; $psize = explode(',',$product-&gt;product_size_values); //$pquantity = $product-&gt;product_quantity; $cat_parentid = 400; $catid = $cat_parentid; $db = JFactory::getDbo(); $query = $db-&gt;getQuery(true); $conditions = array( $db-&gt;quoteName('category_parent_id') . ' = ' .$cat_parentid, $db-&gt;quoteName('product_id') . ' = ' . $pid ); $query-&gt;delete($db-&gt;quoteName('#__hikashop_product_category')); $query-&gt;where($conditions); $db-&gt;setQuery($query); $db-&gt;execute(); $s .= $query . '&lt;br /&gt;'; $query-&gt;clear; $columns = array('product_id', 'category_id', 'category_parent_id'); foreach($psize as $ps){ $catid += $ps; $values = array($pid, $catid, $cat_parentid); $query = $db-&gt;getQuery(true); $query -&gt;insert($db-&gt;quoteName('#__hikashop_product_category')) -&gt;columns($db-&gt;quoteName($columns)) -&gt;values(implode(',', $values)); $db-&gt;setQuery($query); $query = str_replace('INSERT', 'INSERT IGNORE', $query); $db-&gt;setQuery($query); try { $db-&gt;execute(); } catch (Exception $e) { echo $e-&gt;getMessage() . $query; } $s .= $query . '&lt;br /&gt;'; $query-&gt;clear; $catid = $cat_parentid; } echo $product-&gt;product_size_values; echo '&lt;br /&gt;'; echo $s; } }

quest ce qui bloque ?

mon echo donne bien

46,47,48 Code:

DELETE FROM &#96;#__hikashop_product_category&#96; WHERE &#96;category_parent_id&#96; = 400 AND &#96;product_id&#96; = 60 INSERT IGNORE INTO &#96;#__hikashop_product_category&#96; (&#96;product_id&#96;,&#96;category_id&#96;,&#96;category_parent_id&#96;) VALUES (60,446,400) INSERT IGNORE INTO &#96;#__hikashop_product_category&#96; (&#96;product_id&#96;,&#96;category_id&#96;,&#96;category_parent_id&#96;) VALUES (60,447,400) INSERT IGNORE INTO &#96;#__hikashop_product_category&#96; (&#96;product_id&#96;,&#96;category_id&#96;,&#96;category_parent_id&#96;) VALUES (60,448,400)

si je recupere les requetes dans un echo et que je les execute directement dans la base tout marche

merci

Last edit: 7 years 2 months ago by [erickb](/forum/user/4069-erickb "View erickb's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vODk4MTgyLW1ldHRyZS1hLWpvdXItdW5lLXRhYmxlLWFwcmVzLWVucmVnaXN0cmVtZW50LWR1bi1wcm9kdWl0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

- **[erickb](/forum/user/4069-erickb "View erickb's Profile")**
- [![erickb's Avatar](https://www.hikashop.com/media/kunena/core/svg/person.svg)](/forum/user/4069-erickb "View erickb's Profile") Topic Author
- [ Offline](/forum/user/4069-erickb)

Less More

- Posts: 2697
- Thank you received: 74
-
-

7 years 2 months ago -  7 years 2 months ago [\#310395](#310395) by [erickb](/forum/user/4069-erickb "View erickb's Profile")  Replied by *[erickb](/forum/user/4069-erickb "View erickb's Profile")* on topic *[mettre a jour une table apres enregistrement d'un produit](/forum/5-support-en-francais-french-support-/898182-mettre-a-jour-une-table-apres-enregistrement-dun-produit#310395 "-- HikaShop version -- : 4.2.1  Bonjour  j'ai cree un trigger qui marche parfaitement si je le fais sur une copie exacte de la table hikashop&#95;product&#95;category mais qui est sans effet sur la table elle meme et je ne comprend vraiment pas ce qui peut bloquer  quand mon champ hikashot&#95;product.product&#95;size&#95;values change je met a jour hikashop&#95;product&#95;category  si mon hikashop&#95;product.product&#95;size&#95;values = '41,42,46' je rentre 3 lignes dans hikashop&#95;product&#95;category (product&#95;id, category&#95;id) values (new.product&#95;id, 441); (product&#95;id, category&#95;id) values (new.product&#95;id, 442); (product&#95;id, category&#95;id) values (new.product&#95;id, 446);  pourquoi le trigger n'a aucun effet alors que tout marche ? merci pour l'aide")*

je vais faire autrement

merci

Last edit: 7 years 2 months ago by [erickb](/forum/user/4069-erickb "View erickb's Profile").

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzUtc3VwcG9ydC1lbi1mcmFuY2Fpcy1mcmVuY2gtc3VwcG9ydC0vODk4MTgyLW1ldHRyZS1hLWpvdXItdW5lLXRhYmxlLWFwcmVzLWVucmVnaXN0cmVtZW50LWR1bi1wcm9kdWl0P3RtcGw9bWFya2Rvd24=) or [Create an account](/component/users/registration?Itemid=101) to join the conversation.

Board Categories HikaShop Install &amp; Update Product &amp; Category Display Content Creation Sales and Orders Orders management Reports &amp; Statistics Customers Checkout Payment Methods Shipping Methods Import &amp; Export (CSV, XLS…) Specific Features Affilation Taxes Wishlist Vote Carousel &amp; Slider Mass Actions Filters &amp; Search Discount &amp; Coupon Feature Request Integrations Showcase General Talk about HikaShop Development HikaShop 3.0 Beta Translation Commercial Jobs HikaShop Components HikaMarket Market: Feature requests Market: How to? Market: Bug Report HikaSerial General talk about HikaSerial Serial: Bug Report Serial: How to? Support en Français de HikaSerial (French Support) HikaSubscription HikaAuction Auction: Feature requests Auction: How to? Auction: Bug report Hikashop around the world Support en Français (French Support) Russian FAQ. Курс выживания с Hikashop. Частые вопросы и о Расширения Hikashop Наши сайты на Hikashop 日本語版サポート(Japanese Support) Thai German Archives Bug Report How to?

[](/forum/topics/feed/mode-topics?format=feed&type=rss)

Time to create page: 0.095 seconds

[Powered by](/forum/credits) [Kunena Forum](https://www.kunena.org)

[](#top)
