protected function getRates($shipping_id, $items, $address, $total) { $plugin = shopShipping::getPlugin(null, $shipping_id); $weight_unit = $plugin->allowedWeightUnit(); $dimension = shopDimension::getInstance()->getDimension('weight'); if ($weight_unit != $dimension['base_unit']) { foreach ($items as $item_id => $item) { if ($item['weight']) { $items[$item_id]['weight'] = $item['weight'] / $dimension['units'][$weight_unit]['multiplier']; } } } $currency = $plugin->allowedCurrency(); $currrent_currency = wa()->getConfig()->getCurrency(false); if ($currency != $currrent_currency) { $total = shop_currency($total, $currrent_currency, $currency, false); } $rates = $plugin->getRates($items, $address, array('total_price' => $total)); if (is_array($rates)) { $is_html = waRequest::request('html'); foreach ($rates as $r_id => &$r) { $r['id'] = $r_id; $r['rate_html'] = $is_html ? shop_currency_html($r['rate'], $r['currency']) : shop_currency($r['rate'], $r['currency']); $r['rate'] = shop_currency($r['rate'], $r['currency']); } unset($r); return array_values($rates); } return $rates; }
public function execute() { $app_settings_model = new waAppSettingsModel(); $settings = $app_settings_model->get(array('shop', 'yoss')); if ($settings['status'] === 'on') { $query = waRequest::post('query', '', waRequest::TYPE_STRING_TRIM); $page = waRequest::post('page', 1, 'int'); $result = array(); $result['products'] = array(); $result['product_count'] = 0; $collection = new shopProductsCollection('search/query=' . $query); $product_limit = $settings['product_limit']; if (!$product_limit) { $product_limit = $this->getConfig()->getOption('products_per_page'); } $products = $collection->getProducts('*', ($page - 1) * $product_limit, $product_limit); if ($products) { $brands = array(); $categories = array(); $feature_model = new shopFeatureModel(); $result['searh_all_url'] = wa()->getRouteUrl('/frontend/search/query=') . '?query=' . $query; foreach ($products as $p) { $brand_feature = $feature_model->getByCode('brand'); $brand = ''; if ($brand_feature) { $feature_value_model = $feature_model->getValuesModel($brand_feature['type']); $product_brands = $feature_value_model->getProductValues($p['id'], $brand_feature['id']); $brands = array(); foreach ($product_brands as $k => $v) { $brand_id = $feature_value_model->getValueId($brand_feature['id'], $v); $brands[] = array('id' => $brand_id, 'brand' => '<a href="' . wa()->getRouteUrl('shop/frontend/brand', array('brand' => str_replace('%2F', '/', urlencode($v)))) . '">' . $v . '</a>'); } } $category_model = new shopCategoryModel(); $category = $category_model->getById($p['category_id']); $res_category = ''; if ($category) { $res_category = '<a href="' . wa()->getRouteUrl('/frontend/category', array('category_url' => $category['full_url'])) . '">' . $category['name'] . '</a>'; } $result['products'][] = array("name" => $p['name'], "url" => $p['frontend_url'], "image" => $p['image_id'] ? "<img src='" . shopImage::getUrl(array("product_id" => $p['id'], "id" => $p['image_id'], "ext" => $p['ext']), "48x48") . "' />" : "", "price" => shop_currency_html($p['price'], true), "brands" => $brands, "category" => $res_category); } $product_model = new shopProductModel(); $product_count = $collection->count(); $result['product_count'] = $product_count; if ($product_count > ($page - 1) * $product_limit + $product_limit) { $result['next_page'] = $page + 1; } else { $result['next_page'] = false; } } $this->response = $result; } else { $this->response = false; } }
public function execute() { $cart = new shopCart(); $item_id = waRequest::post('id'); $cart_items_model = new shopCartItemsModel(); $item = $cart_items_model->getById($item_id); $is_html = waRequest::request('html'); if ($q = waRequest::post('quantity', 0, 'int')) { if (!wa()->getSetting('ignore_stock_count')) { if ($item['type'] == 'product') { $product_model = new shopProductModel(); $p = $product_model->getById($item['product_id']); $sku_model = new shopProductSkusModel(); $sku = $sku_model->getById($item['sku_id']); // check quantity if ($sku['count'] !== null && $q > $sku['count']) { $q = $sku['count']; $name = $p['name'] . ($sku['name'] ? ' (' . $sku['name'] . ')' : ''); $this->response['error'] = sprintf(_w('Only %d pcs of %s are available, and you already have all of them in your shopping cart.'), $q, $name); $this->response['q'] = $q; } } } $cart->setQuantity($item_id, $q); $this->response['item_total'] = $is_html ? shop_currency_html($cart->getItemTotal($item_id), true) : shop_currency($cart->getItemTotal($item_id), true); } elseif ($v = waRequest::post('service_variant_id')) { $cart->setServiceVariantId($item_id, $v); $this->response['item_total'] = $is_html ? shop_currency_html($cart->getItemTotal($item['parent_id']), true) : shop_currency($cart->getItemTotal($item['parent_id']), true); } $total = $cart->total(); $discount = $cart->discount(); $this->response['total'] = $is_html ? shop_currency_html($total, true) : shop_currency($total, true); $this->response['discount'] = $is_html ? shop_currency_html($discount, true) : shop_currency($discount, true); $this->response['discount_numeric'] = $discount; $this->response['count'] = $cart->count(); if (shopAffiliate::isEnabled()) { $add_affiliate_bonus = shopAffiliate::calculateBonus(array('total' => $total, 'discount' => $discount, 'items' => $cart->items(false))); $this->response['add_affiliate_bonus'] = sprintf(_w("This order will add +%s points to your affiliate bonus."), round($add_affiliate_bonus, 2)); } }
public function execute() { $id = waRequest::post('id'); $cart = new shopCart(); $is_html = waRequest::request('html'); if ($id) { $item = $cart->deleteItem($id); if ($item && !empty($item['parent_id'])) { $item_total = $cart->getItemTotal($item['parent_id']); $this->response['item_total'] = $is_html ? shop_currency_html($item_total, true) : shop_currency($item_total, true); } } $total = $cart->total(); $discount = $cart->discount(); $this->response['total'] = $is_html ? shop_currency_html($total, true) : shop_currency($total, true); $this->response['discount'] = $is_html ? shop_currency_html($discount, true) : shop_currency($discount, true); $this->response['count'] = $cart->count(); if (shopAffiliate::isEnabled()) { $add_affiliate_bonus = shopAffiliate::calculateBonus(array('total' => $total, 'discount' => $discount, 'items' => $cart->items(false))); $this->response['add_affiliate_bonus'] = sprintf(_w("This order will add +%s points to your affiliate bonus."), round($add_affiliate_bonus, 2)); } }
protected function getMetafields($product) { $search = array('{$name}', '{$price}', '{$summary}'); $replace = array(); foreach ($search as $i => $s) { $r = substr($s, 2, -1); if (isset($product[$r])) { if ($r == 'price') { $replace[] = shop_currency_html($product[$r], null, null, true); } else { $replace[] = $product[$r]; } } else { unset($search[$i]); } } $res = array(); foreach (array('meta_title', 'meta_keywords', 'meta_description') as $f) { if (isset($product[$f])) { $res[$f] = str_replace($search, $replace, $product[$f]); } } return $res; }
/** * @param float $val * @param string|bool $currency * @return string */ protected function currencyFormat($val, $currency = true) { return $this->is_html ? shop_currency_html($val, $currency) : shop_currency($val, $currency); }