static function buildNewProductsFeedData($items, $account_id, $profile, $append_feed = false) { if (!$profile || !$profile->id) { WPLA()->logger->info('no profile found, falling back to ListingLoader (Offer)'); return self::buildListingLoaderFeedData($items, $account_id, $append_feed); } $template = new WPLA_AmazonFeedTemplate($profile->tpl_id); if (!$template || !$template->id) { WPLA()->logger->info('no template, falling back to ListingLoader (Offer) - tpl_id: ' . $profile->tpl_id); return self::buildListingLoaderFeedData($items, $account_id, $append_feed); } $columns = $template->getFieldNames(); $profile_fields = maybe_unserialize($profile->fields); // echo "<pre>";print_r($items);echo"</pre>";#die(); // echo "<pre>";print_r($template);echo"</pre>";#die(); // echo "<pre>";print_r($profile);echo"</pre>";#die(); // echo "<pre>";print_r($columns);echo"</pre>";#die(); // echo "<pre>";print_r($profile_fields);echo"</pre>";#die(); if (!$columns) { WPLA()->logger->error('no columns found in template - tpl_id: ' . $profile->tpl_id); WPLA()->logger->info('profile: ' . print_r($profile, 1)); WPLA()->logger->info('template: ' . print_r($template, 1)); WPLA()->logger->info('columns: ' . print_r($columns, 1)); WPLA()->logger->info('items: ' . print_r($items, 1)); return ''; } // add variation columns // (not really needed - if the template doesn't already have them, variations are probably not allowed or the template is outdated) if ($template->name != 'Offer') { // $profile_details = maybe_unserialize( $profile->details ); // $variations_mode = isset( $profile_details['variations_mode'] ) ? $profile_details['variations_mode'] : 'default'; // if ( $variations_mode != 'flat' ) { // $columns[] = 'parent-sku'; // $columns[] = 'parentage'; // $columns[] = 'relationship-type'; // $columns[] = 'variation-theme'; // } } // header $csv_header = 'TemplateType=' . $template->name . "\t" . 'Version=' . $template->version . str_repeat("\t", sizeof($columns) - 2) . "\n"; $csv_header .= join("\t", $columns) . "\n"; if ($template->name != 'Offer') { $csv_header .= join("\t", $columns) . "\n"; } $csv_body = ''; // loop products foreach ($items as $item) { // get WooCommerce product data $product_id = $item['post_id']; $product = get_product($product_id); if (!$product) { continue; } if (!$item['sku']) { continue; } WPLA()->logger->debug('processing item ' . $item['sku'] . ' - ID ' . $product_id); // reset row cache WPLA()->memcache->clearColumnCache(); // process product foreach ($columns as $col) { $value = self::parseProductColumn($col, $item, $product, $profile); $value = apply_filters('wpla_filter_listing_feed_column', $value, $col, $item, $product, $profile, $template->name); $value = str_replace(array("\t", "\n", "\r"), ' ', $value); // make sure there are no tabs or line breaks in any field $csv_body .= $value . "\t"; WPLA()->memcache->setColumnValue($product->sku, $col, $value); } $csv_body .= "\n"; } // check if any rows were created if (!$csv_body) { return self::return_csv_object(); } // only return body when appending feed if ($append_feed) { return self::return_csv_object($csv_body, '', $template->name); } // return csv object return self::return_csv_object($csv_body, $csv_header, $template->name); }