Exclude some products during import
-
Hello, first of all congratulations to the whole team for this great plugin.
I want to exclude some products during import.
Sample 1) As a price for a product with a {price[1]} path, I want to exclude products with unit 10 and below.
Sample 2) As a product category with path {category[1]}, I want to exclude the category named ‘cosmetics’ in it
Sample 3) Some products with SKU codes, for example: 1245, 2841, 3985, 4249, etc. I want to list and exclude SKU codes.
Thanks in advance for your help. I will be grateful if you can help with sample code.
-
I think solved it with “add filtering options” for category and price.
Do you have a suggestion for the SKU?
Is there a place to add as a bulk list, what do you recommend?
@ibrahimpak Nice job with the category and price filtering.
You should be able to filter via SKU the same way using an XPath filter.
The XPath “equal”, “not equal”, and “or” operators should be helpful.
XPath Operators – https://www.w3schools.com/xml/xpath_operators.aspWPAllImport XPath Filtering Docs – https://www.wpallimport.com/documentation/advanced/filtering-with-xpath/
If you still need help, you can share your CSV here and someone may be able to point you in the right direction.
Hello @aakash8
Thanks for your advice on xPath.
I also have two separate edits for the header, how can I put them together?
[str_replace(",", "", {title[1]})]
[my_fix_title({title[1]})]This is how I ensured that there were two codes in one column.
[my_fix_title(str_replace("Test", "Test2", {ProductName[1]}))]-
This reply was modified 4 years, 2 months ago by
ibrahimpak.
@ibrahimpak Nice job! Still need help with anything?
Feel free to mark this topic as “Resolved” if not@aakash8 I want one more suggestion from you.
I’m using the code snippet below to clean up the ID number at the end of the header.
function my_fix_title( $title ) { $title = explode( ' ', $title ); array_pop( $title ); return implode( ' ', $title ); }The code works but sometimes it also deletes words.
What can I do to have it clear only digits in the range 0-9?
Below is an example of a file. The header output will be as follows.
1. Title ) TRANSFORMACION Tam Otomatik Çanta Boy
2. Title ) TRANSFORMACION Carson Trafik Emniyet
3. Title ) ModaCar Magnus Trafik Emniyet Seti (only this works right)
<?xml version="1.0"?> <Products> <Product> <Code>7440000714281</Code> <ProductType>Asıl</ProductType> <MainProductCode/> <Barcode>7440000714281</Barcode> <UnitInStock>11</UnitInStock> <IsActive>1</IsActive> <ModelNumber>HBCV00000P6NDP</ModelNumber> <Mark>Transformacion</Mark> <ProductName>TRANSFORMACION Tam Otomatik Çanta Boy Şemsiye </ProductName> <Description> Şemsiyeler </Description> <Price>53,20</Price> <Currency>YTL</Currency> <Vat>18</Vat> <Desi>1</Desi> <MainGroupCode>21201</MainGroupCode> <MainGroup>Unisex Aksesuar ve Bakım</MainGroup> <EndGroupCode>21136</EndGroupCode> <EndGroup>Şemsiye</EndGroup> <PictureCode>https://www.arabayaservis.com/productimages/164797/big/7430000714281.jpg</PictureCode> </Product> <Product> <Code>7440000428900</Code> <ProductType>Asıl</ProductType> <MainProductCode/> <Barcode>7440000428900</Barcode> <UnitInStock>6</UnitInStock> <IsActive>1</IsActive> <ModelNumber>HBCV000014NRB5</ModelNumber> <Mark>Transformacion</Mark> <ProductName>TRANSFORMACION Carson Trafik Emniyet Seti </ProductName> <Description> Emniyet Setleri </Description> <Price>115,66</Price> <Currency>YTL</Currency> <Vat>18</Vat> <Desi>1</Desi> <MainGroupCode>21130</MainGroupCode> <MainGroup>ARAC AKSESUAR</MainGroup> <EndGroupCode>12954</EndGroupCode> <EndGroup>Trafik Yol Yardımcı Ürünler</EndGroup> <PictureCode>https://www.arabayaservis.com/productimages/177923/big/be480024-2d00-4abb-b5ba-3a94327a7a65.jpg</PictureCode> </Product> <Product> <Code>7410000428901</Code> <ProductType>Asıl</ProductType> <MainProductCode/> <Barcode>74100004289012</Barcode> <UnitInStock>6</UnitInStock> <IsActive>1</IsActive> <ModelNumber>HBCV000013B5HJ</ModelNumber> <Mark>ModaCar</Mark> <ProductName>ModaCar Magnus Trafik Emniyet Seti 428901</ProductName> <Description> Emniyet Setleri </Description> <Price>160,93</Price> <Currency>YTL</Currency> <Vat>18</Vat> <Desi>1</Desi> <MainGroupCode>21130</MainGroupCode> <MainGroup>ARAC AKSESUAR</MainGroup> <EndGroupCode>12954</EndGroupCode> <EndGroup>Trafik Yol Yardımcı Ürünler</EndGroup> <PictureCode>https://www.arabayaservis.com/productimages/175176/big/7410000428901.jpg</PictureCode> </Product> </Products>Also below is another code. How can this code only work for prices of 50 and above?
function round_price( $price = null, $multiplier = 1, $nearest = .01, $minus = 0 ) { if ( !empty( $price ) ) { // strip any extra characters from price $price = preg_replace("/[^0-9,.]/", "", $price); // perform calculations return ( round ( ( $price * $multiplier ) / $nearest ) * $nearest ) - $minus; }Hi @ibrahimpak,
What can I do to have it clear only digits in the range 0-9?
You can use end() and ctype_digit() to test the value before you use array_pop() on it. For example:
function my_fix_title( $title ) { $title = explode( ' ', $title ); $final_value = end( $title ); if ( ctype_digit( $final_value ) ) { array_pop( $title ); } return implode( ' ', $title ); }Also below is another code. How can this code only work for prices of 50 and above?
After the preg_replace function, you can use another IF statement to make sure the $price value is greater than 50 before doing the calculations: https://www.w3schools.com/php/php_if_else.asp.
Hello @wpallimport
I tried the code and the titles look great.
I would appreciate it if you could help me with the price rounding price limit.
Thank you so much!
I tried it and unfortunately couldn’t get it to work for the price of 50 and above.
I will be grateful for your help.
function round_price( $price = null, $multiplier = 1, $nearest = .01, $minus = 0 ) { if ( !empty( $price ) ) { // strip any extra characters from price $price = preg_replace("/[^0-9,.]/", "", $price); // perform calculations if (round_price($price > 50)) { echo "true"; } else { echo "false"; } return ( round ( ( $price * $multiplier ) / $nearest ) * $nearest ) - $minus; } }@ibrahimpak If your goal is to only round the price if it’s 50 or above, put this as the function
function round_price( $price = null, $multiplier = 1, $nearest = .01, $minus = 0 ) { if ( (!empty($price)) and ($price >= 50) ) { // Remove any extra characters from price. $price = preg_replace("/[^0-9,.]/", "", $price); // Perform calculations and return rounded price. return ( round ( ( $price * $multiplier ) / $nearest ) * $nearest ) - $minus; } }-
This reply was modified 4 years, 2 months ago by
Aakash.
Thank you @aakash8
For prices of 50 and above, the code works as I want it to.
It does not take into account prices below 50. It leaves it blank.
Is it possible to leave them as they are?
@ibrahimpak This may work:
function round_price( $price = null, $multiplier = 1, $nearest = .01, $minus = 0 ) { if ( (!empty($price)) and ($price >= 50) ) { // Remove any extra characters from price. $price = preg_replace("/[^0-9,.]/", "", $price); // Perform calculations and return rounded price. return ( round ( ( $price * $multiplier ) / $nearest ) * $nearest ) - $minus; } else { return $price: } }The snippet works as I want it to.
Prices of 50 and above are rounded.
Prices of 50 and below are left as they are.
Thanks for everything!
-
This reply was modified 4 years, 2 months ago by
The topic ‘Exclude some products during import’ is closed to new replies.