Problem with automatic product catalog catagol
-
Hi, I have a problem with the product feed generation. I wrote a function for adding sale price and some attributes to the feed. But there’s a problem: if I manually refresh the product feed via the pixel caffeine setting page the feed is correct (there are all the values insered by the function) but if the feed automatically refresh (every hour), the sale price and the discount percentage (mapped in the custom field) are blank.
How can i resolve this bug?The function code
add_filter('aepc_feed_item', function($fields, \PixelCaffeine\ProductCatalog\FeedMapper $item) { if ($product = wc_get_product($item->get_item()->get_id())) { $fields['g:brand'] = $product->get_attribute('pa_marca'); $fields['g:color'] = $product->get_attribute('pa_colore'); if($product->is_on_sale()){ if( $product->is_type('variable')){ $percentages = array(); $prices = $product->get_variation_prices(); foreach( $prices['price'] as $key => $price ){ if( $prices['regular_price'][$key] !== $price ){ $pezzi[] = $price; $percentages[] = round(100 - ($prices['sale_price'][$key] / $prices['regular_price'][$key] * 100)); } } $field['g:sale_price'] = '' + max($prezzi); + ' EUR'; $fields['g:custom_label_1'] = max($percentages) . '%'; } else{ $field['g:sale_price'] = '' + $product->get_sale_price() + ' EUR'; $regular_price = (float) $product->get_regular_price(); $sale_price = (float) $product->get_sale_price(); $percentage = round(100 - ($sale_price / $regular_price * 100)); $fields['g:custom_label_1'] = $percentage . '%'; } $fields['g:sale_price_effective_date'] = "2020-01-01T23:59+00:00/2030-01-01T23:59+00:00"; } } return $fields; }, 10, 2);
Entry manual refresh
<entry> <g:id>030 NERO</g:id> <g:title> <![CDATA[ 030 DELICE STIVALETTO NERO ]]> </g:title> <g:description> <![CDATA[ Stivaletto con tacco basso prodotto dell’azienda Chiarini Codice: 030 Colore: delice nero ]]> </g:description> <g:link>https://www.mirell.it/prodotto/030-delice-nero/</g:link> <g:brand>Chiarini</g:brand> <g:condition>new</g:condition> <g:availability>in stock</g:availability> <g:price>179 EUR</g:price> <g:checkout_url>https://www.mirell.it/prodotto/030-delice-nero/</g:checkout_url> <g:image_link>https://www.mirell.it/wp-content/uploads/2019/11/030-DELICE-NERO1.jpg</g:image_link> <g:sale_price>143.2 EUR</g:sale_price> <g:additional_image_link>https://www.mirell.it/wp-content/uploads/2019/11/030-DELICE-NERO.jpg</g:additional_image_link> <g:google_product_category>Clothing & Accessories</g:google_product_category> <g:color>Nero</g:color> <g:custom_label_1>20%</g:custom_label_1> <g:sale_price_effective_date>2020-01-01T23:59+00:00/2030-01-01T23:59+00:00</g:sale_price_effective_date> </entry>
Entry automatic refresh
<entry> <g:id>030 NERO</g:id> <g:title> <![CDATA[ 030 DELICE STIVALETTO NERO ]]> </g:title> <g:description> <![CDATA[ Stivaletto con tacco basso prodotto dell’azienda Chiarini Codice: 030 Colore: delice nero ]]> </g:description> <g:link>https://www.mirell.it/prodotto/030-delice-nero/</g:link> <g:brand>Chiarini</g:brand> <g:condition>new</g:condition> <g:availability>in stock</g:availability> <g:price>179 EUR</g:price> <g:checkout_url>https://www.mirell.it/prodotto/030-delice-nero/</g:checkout_url> <g:image_link>https://i1.wp.com/www.mirell.it/wp-content/uploads/2019/11/030-DELICE-NERO1.jpg?fit=600%2C750&ssl=1</g:image_link> <g:additional_image_link>https://www.mirell.it/wp-content/uploads/2019/11/030-DELICE-NERO.jpg</g:additional_image_link> <g:google_product_category>Clothing & Accessories</g:google_product_category> <g:color>Nero</g:color> </entry>
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘Problem with automatic product catalog catagol’ is closed to new replies.