/** * On the scheduled action hook, run the function. */ function lightspeed_import_manufacturers() { // do import every hour //empty the directory to build new xml files $files = glob($this->XML_dir_manufacturers . '*'); // get all file names foreach ($files as $file) { // iterate files if (is_file($file)) { unlink($file); } // delete file } $emitter = 'https://api.merchantos.com/API/Account/' . LI()->API_account . '/Manufacturer'; $offset = 0; $limit = 100; $c = $j = 0; $feeds = array(); $grouped_results = null; $xml_query_string = 'limit=' . $limit . '&offset=' . $offset; $manufacturers = LI()->api->makeAPICall("Account.Manufacturer", "Read", null, null, $emitter, $xml_query_string); $c = $manufacturers->attributes()->count; syslog(LOG_DEBUG, "Manufacturer Count=" . $c); $loop_size = ceil($c / $limit); for ($i = 0; $i < $loop_size; $i++) { $offset = $limit * $i; $feeds[] = '&limit=' . $limit . '&offset=' . $offset; } // For each feed, store the results as an array foreach ($feeds as $feed) { $manufacturers = LI()->api->makeAPICall("Account.Manufacturer", "Read", null, null, $emitter, $feed); if (!empty($manufacturers)) { if ($j == 0) { $grouped_results = $manufacturers; } else { $dom_grouped_results = dom_import_simplexml($grouped_results); $dom_manufacturers = dom_import_simplexml($manufacturers); foreach ($dom_manufacturers->childNodes as $node) { $dom_manufacturer = $dom_grouped_results->ownerDocument->importNode($node, TRUE); $dom_grouped_results->appendChild($dom_manufacturer); } } } $j++; } $grouped_results->asXML($this->XML_dir_manufacturers . 'lightspeed-webstore-manufacturers.xml'); }
/** * Output featured products * * @access public * @param array $atts * @return string */ public static function lightspeed_featured_products($atts) { global $woocommerce_loop, $products, $product; extract(shortcode_atts(array('per_page' => '12', 'columns' => '4', 'orderby' => 'date', 'order' => 'desc'), $atts)); $woocommerce_loop['columns'] = $columns; $products = LI()->LI_cache->get("lightspeed_featured_products"); ob_start(); if ($products == null) { echo "getting from API"; $emitter = 'https://api.merchantos.com/API/Account/' . LI()->API_account . '/ItemMatrix'; if (!empty($tag) || $filter == "new") { $xml_query_string = 'limit=100&orderby=timeStamp&orderby_desc=1&load_relations=["ItemECommerce","Tags","Images"]'; } else { $xml_query_string = 'tag=beyondyoga&limit=100&load_relations=["ItemECommerce","Tags","Images"]'; } $products = LI()->api->makeAPICall("Account.ItemMatrix", "Read", null, null, $emitter, $xml_query_string); //$wp_session = WP_Session::get_instance(); $products = xml2array($products); LI()->LI_cache->set("lightspeed_featured_products", $products, 36000); } woocommerce_product_loop_start(); foreach ($products as $prod) { foreach ($prod as $product) { wc_get_template_part('content', 'lightspeedproduct'); } } // end of the loop. woocommerce_product_loop_end(); return '<div class="woocommerce columns-' . $columns . '">' . ob_get_clean() . '</div>'; }