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

#   Use onBeforeProductCreate with xml inventory file

##

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

Less More

- Posts: 128
- Thank you received: 3
-
-

10 years 6 months ago [\#237369](#237369) by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")  *[Use onBeforeProductCreate with xml inventory file](/forum/31-development/883978-use-onbeforeproductcreate-with-xml-inventory-file#237369 "-- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.5.0 -- PHP version -- : 5.3.24  I have a xml inventory file that gets downloaded from a server once a day. It is formatted like  I'm trying to create a plugin that once the file is downloaded it uses simpleXML to load the file as an object, then loop through all items and create products for those that do not have a quantity of 0. I'm very new to working with the triggers in Hikashop. This is part of what I have so far.  As I said this is all new to me. My main questions are am I correct about calling the onBeforeProductCreate trigger in the code above, how would I use the onBeforeProductCreate trigger to assign the appropriate xml attributes to the appropriate product table column for each product, and does the trigger itself actually save the product?")* was created by *[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")*

-- HikaShop version -- : 2.6.1
-- Joomla version -- : 3.5.0
-- PHP version -- : 5.3.24

I have a xml inventory file that gets downloaded from a server once a day. It is formatted like Code:

&lt;?xml version='1.0' standalone='yes'?&gt; &lt;InventoryDocument 20160407 11:29:36 AM&gt; &lt;Item&gt; &lt;ItemNo&gt;035388227&lt;/ItemNo&gt; &lt;item_desc&gt;BRN XBOLT WH ATACS AU 7MM 26B&lt;/item_desc&gt; &lt;msp&gt;854.44&lt;/msp&gt; &lt;retail_price&gt;1029.99&lt;/retail_price&gt; &lt;base_price&gt;804.99&lt;/base_price&gt; &lt;sale_price&gt;&lt;/sale_price&gt; &lt;sale_ends&gt;&lt;/sale_ends&gt; &lt;quantity&gt;0&lt;/quantity&gt; &lt;upc_code&gt;023614440741&lt;/upc_code&gt; &lt;manufacturer&gt;Browning&lt;/manufacturer&gt; &lt;gun_type&gt;Rifle: Bolt Action&lt;/gun_type&gt; &lt;model_series&gt;X-Bolt&lt;/model_series&gt; &lt;caliber&gt;7MM&lt;/caliber&gt; &lt;action&gt;Bolt Action&lt;/action&gt; &lt;mag_cap&gt;3+1&lt;/mag_cap&gt; &lt;finish&gt;Matte Blue&lt;/finish&gt; &lt;stock&gt;Composite&#124; A-TACS AU Camo&lt;/stock&gt; &lt;sights&gt;No Sights&lt;/sights&gt; &lt;barrle_length&gt;26 Free Floating&#124; Target Crown&lt;/barrle_length&gt; &lt;overall_length&gt;46.75&lt;/overall_length&gt; &lt;features&gt;Sling Swivel Studs&#124; Adjustable Feather Trigger&lt;/features&gt; &lt;/Item&gt; ... &lt;/InventoryDocument 20160407 11:29:36 AM&gt;

I'm trying to create a plugin that once the file is downloaded it uses simpleXML to load the file as an object, then loop through all items and create products for those that do not have a quantity of 0. I'm very new to working with the triggers in Hikashop. This is part of what I have so far. Code:

function _updateProducts($path){ //Get a db connection $db = JFactory::getDbo(); //Create a new query object $query = $db-&gt;getQuery(true); //select products from categories chosen in plugin $query -&gt;select($db-&gt;quoteName(array('a.category_id','a.category_name','b.category_id','b.product_id','c.product_id','c.product_code','c.product_quantity','c.product_published','c.upc')) -&gt;from($db-&gt;quoteName('#__hikashop_category','a')) -&gt;join('LEFT',$db-&gt;quoteName('#__hikashop_product_category','b').' ON ('.$db-&gt;quoteName('a.category_id').' = '.$db-&gt;quoteName('b.category_id').')') -&gt;join('LEFT',$db-&gt;quoteName('#__hikashop_product','c').' ON ('.$db-&gt;quoteName('b.product_id').' = '.$db-&gt;quoteName('c.product_id').')') -&gt;where($db-&gt;quoteName('a.category_id').' IN ('.implode(',',$plugin-&gt;params['category_name']).')'; //Reset the query using our newly populated object $db-&gt;setQuery($query); //Load the result as an object $results = $db-&gt;loadObjectList(); //create array to store product code with upc $product_sku_upc = array(); //store product codes and upcs into array foreach($results as $result){ $product_sku_upc[$result-&gt;product_code]= $result-&gt;upc; } //convert XML file to object $xml = simplexml_load_file(JPATH_ROOT.DS.$path); //loop through items and create product if it doesn't already exist and there is quantity in stock foreach($xml-&gt;Item as $product){ if(array_key_exists($product-&gt;ItemNo,$product_sku_upc) &#124;&#124; $product-&gt;quantity == 0 &#124;&#124; $product-&gt;quantity == "A*"){ continue; }else{ //this is what I'm not sure about onBeforeProductCreate($product,true); } } }

As I said this is all new to me. My main questions are am I correct about calling the onBeforeProductCreate trigger in the code above, how would I use the onBeforeProductCreate trigger to assign the appropriate xml attributes to the appropriate product table column for each product, and does the trigger itself actually save the product?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4Mzk3OC11c2Utb25iZWZvcmVwcm9kdWN0Y3JlYXRlLXdpdGgteG1sLWludmVudG9yeS1maWxlP3RtcGw9bWFya2Rvd24=) 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: 86541
- Thank you received: 14304
-
-

10 years 6 months ago [\#237373](#237373) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Use onBeforeProductCreate with xml inventory file](/forum/31-development/883978-use-onbeforeproductcreate-with-xml-inventory-file#237373 "-- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.5.0 -- PHP version -- : 5.3.24  I have a xml inventory file that gets downloaded from a server once a day. It is formatted like  I'm trying to create a plugin that once the file is downloaded it uses simpleXML to load the file as an object, then loop through all items and create products for those that do not have a quantity of 0. I'm very new to working with the triggers in Hikashop. This is part of what I have so far.  As I said this is all new to me. My main questions are am I correct about calling the onBeforeProductCreate trigger in the code above, how would I use the onBeforeProductCreate trigger to assign the appropriate xml attributes to the appropriate product table column for each product, and does the trigger itself actually save the product?")*

Hi,

Triggers can't be called like that and that trigger won't save your product object and it also won't convert your XML tag names to the necessary names for HikaShop.

I guess that the simplest will be to base your code on the code of the plugin plugins/hikashop/datafeed/ which downloads a CSV file and import it with the import system of HikaShop.

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

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

Less More

- Posts: 128
- Thank you received: 3
-
-

10 years 6 months ago [\#239375](#239375) by [deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")  Replied by *[deuce4884](/forum/user/38332-deuce4884 "View deuce4884's Profile")* on topic *[Use onBeforeProductCreate with xml inventory file](/forum/31-development/883978-use-onbeforeproductcreate-with-xml-inventory-file#239375 "-- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.5.0 -- PHP version -- : 5.3.24  I have a xml inventory file that gets downloaded from a server once a day. It is formatted like  I'm trying to create a plugin that once the file is downloaded it uses simpleXML to load the file as an object, then loop through all items and create products for those that do not have a quantity of 0. I'm very new to working with the triggers in Hikashop. This is part of what I have so far.  As I said this is all new to me. My main questions are am I correct about calling the onBeforeProductCreate trigger in the code above, how would I use the onBeforeProductCreate trigger to assign the appropriate xml attributes to the appropriate product table column for each product, and does the trigger itself actually save the product?")*

I think I can do as you said by basing my code off of the datafeed plugin because I can get my inventory file in a csv format as well. My one thing is about the "Price fee" parameter in the plugin. Is there anyway to use the datafeed to set multiple prices for each product based on the user group. Example if my "Price fee" is 15% can I assign this price to my "customer" user group and then add another parameter like "Dealer price fee" and say it is 10% and assign that price to my "dealer" user group for each product?

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4Mzk3OC11c2Utb25iZWZvcmVwcm9kdWN0Y3JlYXRlLXdpdGgteG1sLWludmVudG9yeS1maWxlP3RtcGw9bWFya2Rvd24=) 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: 86541
- Thank you received: 14304
-
-

10 years 6 months ago [\#239381](#239381) by [nicolas](/forum/user/63-nicolas "View nicolas's Profile")  Replied by *[nicolas](/forum/user/63-nicolas "View nicolas's Profile")* on topic *[Use onBeforeProductCreate with xml inventory file](/forum/31-development/883978-use-onbeforeproductcreate-with-xml-inventory-file#239381 "-- HikaShop version -- : 2.6.1 -- Joomla version -- : 3.5.0 -- PHP version -- : 5.3.24  I have a xml inventory file that gets downloaded from a server once a day. It is formatted like  I'm trying to create a plugin that once the file is downloaded it uses simpleXML to load the file as an object, then loop through all items and create products for those that do not have a quantity of 0. I'm very new to working with the triggers in Hikashop. This is part of what I have so far.  As I said this is all new to me. My main questions are am I correct about calling the onBeforeProductCreate trigger in the code above, how would I use the onBeforeProductCreate trigger to assign the appropriate xml attributes to the appropriate product table column for each product, and does the trigger itself actually save the product?")*

Hi,

In that case, instead of having different prices, why not just create discounts restricted to the different user groups so that the dsicount will be applied automatically to the price of the products ? That way, you keep one price and you can easily adjust your fee for special user groups.

Please [Log in](/login?return=aHR0cHM6Ly93d3cuaGlrYXNob3AuY29tL2ZvcnVtLzMxLWRldmVsb3BtZW50Lzg4Mzk3OC11c2Utb25iZWZvcmVwcm9kdWN0Y3JlYXRlLXdpdGgteG1sLWludmVudG9yeS1maWxlP3RtcGw9bWFya2Rvd24=) 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.040 seconds

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