function get_category($id) { $params = array(array("alias" => "c", "action" => "categories", "params" => array("parent" => $id)), array("alias" => "p", "action" => "products", "params" => array("category" => $id)), array("alias" => "pf", "action" => "profile")); if ($id > 0) { $params[] = array('alias' => 'category', "action" => "category", "params" => array("id" => $id)); } $batch_result = $this->ecwid_api->get_batch_request($params); $category = $id > 0 ? $batch_result['category'] : null; $categories = $batch_result["c"]; $products = $batch_result["p"]; $profile = $batch_result["pf"]; $return = $this->_l(''); if (!is_null($category)) { $return .= $this->_l('<h2>' . esc_html($category['name']) . '</h2>'); $return .= $this->_l('<div>' . $category['description'] . '</div>'); } if (is_array($categories)) { foreach ($categories as $category) { $category_url = ecwid_get_category_url($category); $category_name = $category["name"]; $return .= $this->_l('<div class="ecwid_catalog_category_name">', 1); $return .= $this->_l('<a href="' . esc_attr($category_url) . '">' . esc_html($category_name) . '</a>'); $return .= $this->_l('</div>', -1); } } if (is_array($products)) { foreach ($products as $product) { $product_url = ecwid_get_product_url($product); $product_name = $product['name']; $product_price = $product['price'] . ' ' . $profile['currency']; $return .= $this->_l('<div>', 1); $return .= $this->_l('<span class="ecwid_product_name">', 1); $return .= $this->_l('<a href="' . esc_attr($product_url) . '">' . esc_html($product_name) . '</a>'); $return .= $this->_l('</span>', -1); $return .= $this->_l('<span class="ecwid_product_price">' . esc_html($product_price) . '</span>'); $return .= $this->_l('</div>', -1); } } return $return; }
function get_category($id) { $params = array(array("alias" => "c", "action" => "categories", "params" => array("parent" => $id)), array("alias" => "p", "action" => "products", "params" => array("category" => $id)), array("alias" => "pf", "action" => "profile")); if ($id > 0) { $params[] = array('alias' => 'category', "action" => "category", "params" => array("id" => $id)); } $batch_result = $this->ecwid_api->get_batch_request($params); $category = $id > 0 ? $batch_result['category'] : null; $categories = $batch_result["c"]; $products = $batch_result["p"]; $profile = $batch_result["pf"]; $return = ''; if (!is_null($category)) { $return .= '<h2>' . esc_html($category['name']) . '</h2>'; $return .= '<div>' . $category['description'] . '</div>'; } if (is_array($categories)) { foreach ($categories as $category) { $category_url = ecwid_get_category_url($category); $category_name = $category["name"]; $return .= sprintf('<div class="ecwid_catalog_category_name"><a href="%s">%s</a></div>' . PHP_EOL, esc_attr($category_url), esc_html($category_name)); } } if (is_array($products)) { foreach ($products as $product) { $product_url = ecwid_get_product_url($product); $product_name = $product["name"]; $product_price = $product["price"] . " " . $profile["currency"]; $return .= "<div>"; $return .= "<span class='ecwid_product_name'><a href='" . esc_attr($product_url) . "'>" . esc_html($product_name) . "</a></span>"; $return .= " <span class='ecwid_product_price'>" . esc_html($product_price) . "</span>"; $return .= "</div>" . PHP_EOL; } } return $return; }