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; }
protected function parseValue($value, $type) { $dimensions = shopDimension::getInstance(); $data = array(); /** * @todo string based pattern * d.d(\s+|\.\.\.?|\s*[\-—]\s*)\d\.\d */ if (strpos($type, '.')) { // if (!is_array($value) || count($value) == 1 && !isset($value['value'])) { $matches = null; $value = trim(is_array($value) ? reset($value) : $value); if (preg_match('/^(.*)\\s+([\\D]+)$/', $value, $matches)) { $value = array('value' => trim($matches[1]), 'unit' => trim($matches[2])); } else { $value = array('value' => trim($value), 'unit' => null); } $values = array_map('trim', preg_split('/\\s*([\\s—]+|\\.\\.\\.?|-\\s+)\\s*/', $value['value'], 2)); if (count($values) > 1) { $value['value'] = array('begin' => $values[0] === '' ? null : $this->castValue('double', $values[0]), 'end' => $values[1] === '' ? null : $this->castValue('double', $values[1])); } else { $value['value'] = array('begin' => $values[0] === '' ? null : $this->castValue('double', $values[0]), 'end' => null); } } $type = preg_replace('/^.+\\./', '', $type); $value['type'] = $type; } if (!empty($value['code'])) { if (strpos($value['code'], '.')) { list($data['type'], $data['unit']) = explode('.', $value['code'], 2); } elseif ($dimension = $dimensions->getDimension(empty($value['type']) ? $value['code'] : $value['type'])) { $data['type'] = !empty($value['type']) ? $value['type'] : $value['code']; $data['unit'] = !empty($value['unit']) ? $value['unit'] : $dimension['base_unit']; } else { $data['unit'] = !empty($value['unit']) ? $value['unit'] : ''; $data['type'] = null; } } else { $data['type'] = !empty($value['type']) ? $value['type'] : ''; if ($dimension = $dimensions->getDimension($data['type'])) { $data['unit'] = !empty($value['unit']) ? $value['unit'] : $dimension['base_unit']; } else { $data['unit'] = !empty($value['unit']) ? $value['unit'] : ''; } } $data['unit'] = $dimensions->fixUnit($data['type'], $data['unit']); $data['begin'] = isset($value['value']['begin']) && $value['value']['begin'] !== '' ? $this->castValue('double', $value['value']['begin']) : null; $data['begin_base_unit'] = $dimensions->convert($data['begin'], $data['type'], null, $data['unit']); $data['end'] = isset($value['value']['end']) && $value['value']['end'] !== '' ? $this->castValue('double', $value['value']['end']) : null; $data['end_base_unit'] = $dimensions->convert($data['end'], $data['type'], null, $data['unit']); return $data; }
protected function parseValue($value, $type) { $dimensions = shopDimension::getInstance(); $data = array(); if (strpos($type, '.')) { $type = preg_replace('/^.+\\./', '', $type); if (!is_array($value) || count($value) == 1) { $matches = null; $value = trim(is_array($value) ? reset($value) : $value); if (preg_match('/^(\\-?\\d+([\\.,]\\d+)?)\\s+(.+)$/', $value, $matches)) { $value = array('value' => $this->castValue('double', $matches[1]), 'unit' => shopDimension::castUnit($type, trim($matches[3]))); } else { $value = array('value' => $this->castValue('double', $value), 'unit' => ''); } } $value['type'] = $type; } if (!empty($value['code'])) { if (strpos($value['code'], '.')) { list($data['type'], $data['unit']) = explode('.', $value['code'], 2); //$dimension = $dimensions->getDimension($data['type']); } elseif ($dimension = $dimensions->getDimension(empty($value['type']) ? $value['code'] : $value['type'])) { $data['type'] = !empty($value['type']) ? $value['type'] : $value['code']; $data['unit'] = !empty($value['unit']) ? $value['unit'] : $dimension['base_unit']; } else { $data['unit'] = !empty($value['unit']) ? $value['unit'] : ''; $data['type'] = null; } } else { $data['type'] = !empty($value['type']) ? $value['type'] : ''; if ($dimension = $dimensions->getDimension($data['type'])) { $data['unit'] = !empty($value['unit']) ? $value['unit'] : $dimension['base_unit']; } else { $data['unit'] = !empty($value['unit']) ? $value['unit'] : ''; } } $data['unit'] = $dimensions->fixUnit($data['type'], $data['unit']); $data['value'] = isset($value['value']) ? $this->castValue('double', $value['value']) : 0; $data['value_base_unit'] = $dimensions->convert($data['value'], $data['type'], null, $data['unit']); return $data; }
/** * Filters collection products by specified conditions. * * @param array $data Product filtering conditions: * 'in_stock_only' => whether only products with positive or unlimited stock count must be returned * 'price_min' => minimum price limit * 'price_max' => maximum price limit * '%feature_code%' => feature value */ public function filters($data) { if ($this->filtered) { return; } $delete = array('page', 'sort', 'order'); foreach ($delete as $k) { if (isset($data[$k])) { unset($data[$k]); } } $config = wa('shop')->getConfig(); if (isset($data['in_stock_only'])) { $this->where[] = '(p.count > 0 OR p.count IS NULL)'; } if (isset($data['price_min']) && $data['price_min'] !== '') { $this->where[] = 'p.max_price >= ' . $this->toFloat(shop_currency($data['price_min'], true, $config->getCurrency(true), false)); unset($data['price_min']); } if (isset($data['price_max']) && $data['price_max'] !== '') { $this->where[] = 'p.min_price <= ' . $this->toFloat(shop_currency($data['price_max'], true, $config->getCurrency(true), false)); unset($data['price_max']); } $feature_model = new shopFeatureModel(); $features = $feature_model->getByField('code', array_keys($data), 'code'); foreach ($data as $feature_code => $values) { if (!is_array($values)) { if ($values === '') { continue; } $values = array($values); } if (isset($features[$feature_code])) { if (isset($values['min']) || isset($values['max']) || isset($values['unit'])) { if (ifset($values['min'], '') === '' && ifset($values['max'], '') === '') { continue; } else { $unit = ifset($values['unit']); $min = $max = null; if (isset($values['min'])) { $min = $values['min']; if ($unit) { $min = shopDimension::getInstance()->convert($min, $features[$feature_code]['type'], null, $unit); } } if (isset($values['max'])) { $max = $values['max']; if ($unit) { $max = shopDimension::getInstance()->convert($max, $features[$feature_code]['type'], null, $unit); } } $fm = $feature_model->getValuesModel($features[$feature_code]['type']); $values = $fm->getValueIdsByRange($features[$feature_code]['id'], $min, $max); } } else { foreach ($values as &$v) { $v = (int) $v; } } if ($values) { $this->addJoin('shop_product_features', 'p.id = :table.product_id AND :table.feature_id = ' . (int) $features[$feature_code]['id'], ':table.feature_value_id IN (' . implode(',', $values) . ')'); $this->group_by = 'p.id'; } else { $this->where[] = '0'; } } } $this->filtered = true; }
public static function getTypes() { static $types; if (!$types) { $dimensions = shopDimension::getInstance(); $units_list = $dimensions->getList(); $units_index = array_keys($units_list); #single types $single_types = array(); $single_types[] = array('name' => _w('Texts'), 'type' => self::TYPE_VARCHAR, 'available' => 1); $single_types[] = array('name' => _w('Custom number'), 'type' => self::TYPE_DOUBLE, 'available' => 1); $single_types[] = array('name' => _w('Color'), 'type' => self::TYPE_COLOR, 'available' => 1); $numerical_types = array(); $numerical_types[] = array('name' => _w('Custom number'), 'group' => _w('Numerical'), 'type' => '%s.' . self::TYPE_DOUBLE, 'alias' => array(self::TYPE_DIMENSION . '.' . self::TYPE_DOUBLE => self::TYPE_DOUBLE), 'multiple' => false, 'selectable' => false, 'available' => 2); foreach ($units_index as $unit) { $type = array('type' => '%s' . '.' . self::TYPE_DIMENSION . '.' . $unit, 'alias' => array(self::TYPE_RANGE . '.' . self::TYPE_DIMENSION . '.' . $unit => self::TYPE_RANGE . '.' . $unit, self::TYPE_DIMENSION . '.' . self::TYPE_DIMENSION . '.' . $unit => self::TYPE_DIMENSION . '.' . $unit), 'available' => 2); if ($dimension = $dimensions->getDimension($unit)) { if (empty($type['name'])) { $type['name'] = $dimension['name']; } $count = count($dimension['units']); $units = array_slice(array_values($dimension['units']), 0, min(4, $count)); if ($count > 5) { $units[] = array('name' => '...'); } foreach ($units as &$u) { $u = $u['name']; } unset($u); $type['short_name'] = $type['name']; $type['name'] .= " (" . implode(', ', $units) . ")"; } else { $type['available'] = 0; } $single_types[] = $type; $numerical_types[$unit] = $type; } $types = array(); $types[] = array('name' => _w('Custom text (input)'), 'type' => self::TYPE_VARCHAR, 'multiple' => false, 'selectable' => false, 'available' => 2); $types[] = array('name' => _w('HTML (textarea)'), 'type' => self::TYPE_TEXT, 'multiple' => false, 'selectable' => false, 'available' => 2); $types[] = array('name' => _w('Yes/No toggle (boolean)'), 'type' => self::TYPE_BOOLEAN, 'multiple' => false, 'selectable' => false, 'available' => 2); /* Shortcuts */ $types[] = array('name' => _w('Color'), 'type' => self::TYPE_COLOR, 'multiple' => true, 'selectable' => true, 'available' => 2); foreach (array('weight', 'length') as $unit) { if (isset($numerical_types[$unit])) { $type = $numerical_types[$unit]; $type += array('multiple' => false, 'selectable' => false, 'available' => 2); if (strpos($type['type'], '%s') !== false) { $type['type'] = sprintf($type['type'], self::TYPE_DIMENSION); if (!empty($type['alias']) && isset($type['alias'][$type['type']])) { $type['type'] = $type['alias'][$type['type']]; } } if (!empty($type['short_name'])) { $type['name'] = $type['short_name']; } $types[] = $type; } } /* Numerical */ $types[] = array('name' => _w('Value'), 'group' => _w('Numerical'), 'type' => self::TYPE_DIMENSION . '.*', 'multiple' => false, 'selectable' => false, 'available' => 2, 'subtype' => self::extendSubtypes($numerical_types, self::TYPE_DIMENSION)); /** * $types[] = array( * 'name' => _w('Date'), * 'group' => _w('Numerical'), * 'type' => 'date', * 'multiple' => false, * 'selectable' => false, * 'available' => 0, * ); */ $types[] = array('name' => _w('Range'), 'group' => _w('Numerical'), 'type' => self::TYPE_RANGE . '.*', 'multiple' => false, 'selectable' => false, 'available' => 2, 'subtype' => self::extendSubtypes($numerical_types, self::TYPE_RANGE)); $types[] = array('name' => _w('Value') . ' × ' . _w('Value'), 'group' => _w('Numerical'), 'type' => self::TYPE_2D . '.*', 'multiple' => false, 'selectable' => false, 'available' => 1, 'subtype' => self::extendSubtypes($numerical_types, self::TYPE_2D)); $types[] = array('name' => _w('Value') . ' × ' . _w('Value') . ' × ' . _w('Value'), 'group' => _w('Numerical'), 'type' => self::TYPE_3D . '.*', 'multiple' => false, 'selectable' => false, 'available' => 1, 'subtype' => self::extendSubtypes($numerical_types, self::TYPE_3D)); /* Selectable */ $types[] = array('name' => _w('Select'), 'group' => _w('Selectable'), 'type' => '*', 'multiple' => false, 'selectable' => true, 'available' => 1, 'subtype' => self::extendSubtypes($single_types, self::TYPE_DIMENSION)); /** TODO * $types[] = array( * 'name' => 'Radiobuttons', * 'group' => _w('Selectable'), * 'type' => '*', * 'multiple' => false, * 'selectable' => true, * 'available' => 0, * 'subtype' => & $single_types, * ); */ $types[] = array('name' => _w('Checkboxes (multiple choice)'), 'group' => _w('Selectable'), 'type' => '*', 'multiple' => true, 'selectable' => true, 'available' => 1, 'subtype' => self::extendSubtypes($single_types, self::TYPE_DIMENSION)); /* divider */ $types[] = array('name' => _w('Divider'), 'group' => _w('Other'), 'type' => self::TYPE_DIVIDER, 'multiple' => false, 'selectable' => false, 'available' => 0); } return $types; }
/** * Returns available shipping methods and rates for specified address. * * @param array $address Address data * @param array $items Order items * @param array $params Optional extra parameters: * 'payment' => [int] payment method id for which available shipping methods must be returned * 'currency' => [string] currency code to convert shipping rates to * 'total_price' => [float] arbitrary total order items cost to be taken into account for obtaining shipping rates * @return array */ public static function getShippingMethods($address = null, $items = array(), $params = array()) { $plugin_model = new shopPluginModel(); $options = array(); if (!empty($params[shopPluginModel::TYPE_PAYMENT])) { $options[shopPluginModel::TYPE_PAYMENT] = $params[shopPluginModel::TYPE_PAYMENT]; } $methods = $plugin_model->listPlugins(shopPluginModel::TYPE_SHIPPING, $options); if ($address !== null) { $config = wa('shop')->getConfig(); /** * @var $config shopConfig */ $result = array(); $currency = isset($params['currency']) ? $params['currency'] : $config->getCurrency(); $dimensions = shopDimension::getInstance(); foreach ($methods as $m) { if ($m['available']) { $plugin = shopShipping::getPlugin($m['plugin'], $m['id']); $plugin_info = $plugin->info($m['plugin']); $plugin_currency = (array) $plugin->allowedCurrency(); $total = null; if ($plugin_currency != $currency) { if (!$config->getCurrencies($plugin_currency)) { $result[$m['id']] = array('plugin' => $m['plugin'], 'logo' => $m['logo'], 'icon' => $plugin_info['icon'], 'img' => $plugin_info['img'], 'name' => $m['name'], 'error' => sprintf(_w('Shipping rate was not calculated because required currency %s is not defined in your store settings.'), implode(', ', $plugin_currency)), 'rate' => '', 'currency' => $currency); continue; } } if (isset($params['total_price'])) { if (!in_array($currency, $plugin_currency)) { $total = shop_currency($params['total_price'], $currency, reset($plugin_currency), false); } else { $total = $params['total_price']; } } else { foreach ($items as $item) { if (!empty($item['price'])) { $total += $item['price'] * (isset($item['quantity']) ? $item['quantity'] : 1); } if ($total && !in_array($currency, $plugin_currency)) { $total = shop_currency($total, $currency, reset($plugin_currency), false); } } } $weight_unit = $plugin->allowedWeightUnit(); foreach ($items as &$item) { if (!empty($item['weight'])) { $item['weight'] = $dimensions->convert($item['weight'], 'weight', $weight_unit); } } unset($item); $rates = $plugin->getRates($items, $address ? $address : array(), $total ? array('total_price' => $total) : array()); if (is_array($rates)) { foreach ($rates as $rate_id => $info) { if (is_array($info)) { $rate = is_array($info['rate']) ? max($info['rate']) : $info['rate']; $rate = (double) shop_currency($rate, reset($plugin_currency), $currency, false); $result[$m['id'] . '.' . $rate_id] = array('plugin' => $m['plugin'], 'logo' => $m['logo'], 'icon' => $plugin_info['icon'], 'img' => $plugin_info['img'], 'name' => $m['name'] . (!empty($info['name']) ? ' (' . $info['name'] . ')' : ''), 'rate' => $rate, 'currency' => $currency); } } } elseif (is_string($rates)) { $result[$m['id']] = array('plugin' => $m['plugin'], 'logo' => $m['logo'], 'icon' => $plugin_info['icon'], 'img' => $plugin_info['img'], 'name' => $m['name'], 'error' => $rates, 'rate' => '', 'currency' => $currency); } } } return $result; } else { return $methods; } }
private function getOrderItems($items, $weight_unit) { $product_ids = array(); foreach ($items as $item) { $product_ids[] = $item['product_id']; } $product_ids = array_unique($product_ids); $feature_model = new shopFeatureModel(); $f = $feature_model->getByCode('weight'); if (!$f) { $values = array(); } else { $values_model = $feature_model->getValuesModel($f['type']); $values = $values_model->getProductValues($product_ids, $f['id']); } $m = null; if ($weight_unit) { $dimension = shopDimension::getInstance()->getDimension('weight'); if ($weight_unit != $dimension['base_unit']) { $m = $dimension['units'][$weight_unit]['multiplier']; } } foreach ($items as &$item) { if ($item['type'] == 'product') { if (isset($values['skus'][$item['sku_id']])) { $w = $values['skus'][$item['sku_id']]; } else { $w = isset($values[$item['product_id']]) ? $values[$item['product_id']] : 0; } if ($m !== null) { $w = $w / $m; } $item['weight'] = $w; } else { $item['weight'] = 0; } } unset($item); return $items; }
public function execute() { $id = waRequest::get('order_id'); if (!$id) { throw new waException("Unknown order", 404); } $order = $this->getOrder($id); if (!$order) { $id = shopHelper::decodeOrderId($id); $order = $this->getOrder($id); if (!$order) { throw new waException("Unkown order", 404); } } $product_ids = array(); foreach ($order['items'] as $item) { if ($item['type'] == 'product') { $product_ids[] = $item['product_id']; } } $product_ids = array_unique($product_ids); $form_id = waRequest::get('form_id'); if (strpos($form_id, '.')) { list($type, $form) = explode('.', $form_id, 2); } else { $form = null; $type = $form_id; } $order_params_model = new shopOrderParamsModel(); $params = $order_params_model->get($order['id']); $plugin = self::getPlugin($type, ifempty($params[$type . '_id'])); if ($type == 'shipping') { /* add weight info only for shipping modules */ $feature_model = new shopFeatureModel(); $f = $feature_model->getByCode('weight'); if (!$f) { $weights = array(); } else { $values_model = $feature_model->getValuesModel($f['type']); $weights = $values_model->getProductValues($product_ids, $f['id']); } if ($weights) { $dimension = shopDimension::getInstance()->getDimension('weight'); $weight_unit = $plugin->allowedWeightUnit(); $m = null; if ($weight_unit != $dimension['base_unit']) { $m = $dimension['units'][$weight_unit]['multiplier']; } foreach ($order['items'] as &$item) { if ($item['type'] == 'product') { if (isset($weights['skus'][$item['sku_id']])) { $w = $weights['skus'][$item['sku_id']]; } else { $w = isset($weights[$item['product_id']]) ? $weights[$item['product_id']] : 0; } if ($m !== null) { $w = $w / $m; } $item['weight'] = $w; } } unset($item); } } if (!$plugin) { throw new waException(_w('Printform not found'), 404); } print $plugin->displayPrintForm(ifempty($form, $plugin->getId()), shopPayment::getOrderData($order, $plugin)); exit; }
public function getItems($weight_unit = null) { $items = array(); $cart = new shopCart(); $cart_items = $cart->items(); $product_ids = $sku_ids = array(); foreach ($cart_items as $item) { $product_ids[] = $item['product_id']; $sku_ids[] = $item['sku_id']; } $feature_model = new shopFeatureModel(); $f = $feature_model->getByCode('weight'); if (!$f) { $values = array(); } else { $values_model = $feature_model->getValuesModel($f['type']); $values = $values_model->getProductValues($product_ids, $f['id']); } $m = null; if ($weight_unit) { $dimension = shopDimension::getInstance()->getDimension('weight'); if ($weight_unit != $dimension['base_unit']) { $m = $dimension['units'][$weight_unit]['multiplier']; } } foreach ($cart_items as $item) { if (isset($values['skus'][$item['sku_id']])) { $w = $values['skus'][$item['sku_id']]; } else { $w = isset($values[$item['product_id']]) ? $values[$item['product_id']] : 0; } if ($m !== null) { $w = $w / $m; } $items[] = array('name' => $item['name'], 'price' => $item['price'], 'quantity' => $item['quantity'], 'weight' => $w); } return $items; }
public function execute() { $category = $this->getCategory(); $this->addCanonical(); // breadcrumbs $root_category_id = $category['id']; if ($category['parent_id']) { $breadcrumbs = array(); $path = array_reverse($this->getModel()->getPath($category['id'])); $root_category = reset($path); $root_category_id = $root_category['id']; foreach ($path as $row) { $breadcrumbs[] = array('url' => wa()->getRouteUrl('/frontend/category', array('category_url' => waRequest::param('url_type') == 1 ? $row['url'] : $row['full_url'])), 'name' => $row['name']); } if ($breadcrumbs) { $this->view->assign('breadcrumbs', $breadcrumbs); } } $this->view->assign('root_category_id', $root_category_id); // sort if ($category['type'] == shopCategoryModel::TYPE_DYNAMIC && !$category['sort_products']) { $category['sort_products'] = 'create_datetime DESC'; } if ($category['sort_products'] && !waRequest::get('sort')) { $sort = explode(' ', $category['sort_products']); $this->view->assign('active_sort', $sort[0] == 'count' ? 'stock' : $sort[0]); } elseif (!$category['sort_products'] && !waRequest::get('sort')) { $this->view->assign('active_sort', ''); } $this->view->assign('category', $category); // products $collection = new shopProductsCollection('category/' . $category['id']); // filters if ($category['filter']) { $filter_ids = explode(',', $category['filter']); $feature_model = new shopFeatureModel(); $features = $feature_model->getById(array_filter($filter_ids, 'is_numeric')); if ($features) { $features = $feature_model->getValues($features); } $category_value_ids = $collection->getFeatureValueIds(); $filters = array(); foreach ($filter_ids as $fid) { if ($fid == 'price') { $range = $collection->getPriceRange(); if ($range['min'] != $range['max']) { $filters['price'] = array('min' => shop_currency($range['min'], null, null, false), 'max' => shop_currency($range['max'], null, null, false)); } } elseif (isset($features[$fid]) && isset($category_value_ids[$fid])) { $filters[$fid] = $features[$fid]; $min = $max = $unit = null; foreach ($filters[$fid]['values'] as $v_id => $v) { if (!in_array($v_id, $category_value_ids[$fid])) { unset($filters[$fid]['values'][$v_id]); } else { if ($v instanceof shopRangeValue) { $begin = $this->getFeatureValue($v->begin); if ($min === null || $begin < $min) { $min = $begin; } $end = $this->getFeatureValue($v->end); if ($max === null || $end > $max) { $max = $end; if ($v->end instanceof shopDimensionValue) { $unit = $v->end->unit; } } } else { $tmp_v = $this->getFeatureValue($v); if ($min === null || $tmp_v < $min) { $min = $tmp_v; } if ($max === null || $tmp_v > $max) { $max = $tmp_v; if ($v instanceof shopDimensionValue) { $unit = $v->unit; } } } } } if (!$filters[$fid]['selectable'] && ($filters[$fid]['type'] == 'double' || substr($filters[$fid]['type'], 0, 6) == 'range.' || substr($filters[$fid]['type'], 0, 10) == 'dimension.')) { if ($min == $max) { unset($filters[$fid]); } else { $type = preg_replace('/^[^\\.]*\\./', '', $filters[$fid]['type']); if ($type != 'double') { $filters[$fid]['base_unit'] = shopDimension::getBaseUnit($type); $filters[$fid]['unit'] = shopDimension::getUnit($type, $unit); if ($filters[$fid]['base_unit']['value'] != $filters[$fid]['unit']['value']) { $dimension = shopDimension::getInstance(); $min = $dimension->convert($min, $type, $filters[$fid]['unit']['value']); $max = $dimension->convert($max, $type, $filters[$fid]['unit']['value']); } } $filters[$fid]['min'] = $min; $filters[$fid]['max'] = $max; } } } } $this->view->assign('filters', $filters); $this->setCollection($collection); // fix prices $products = $this->view->getVars('products'); $product_ids = array(); foreach ($products as $p_id => $p) { if ($p['sku_count'] > 1) { $product_ids[] = $p_id; } } if ($product_ids) { $min_price = $max_price = null; $tmp = array(); foreach ($filters as $fid => $f) { if ($fid == 'price') { $min_price = waRequest::get('price_min'); if (!empty($min_price)) { $min_price = (double) $min_price; } else { $min_price = null; } $max_price = waRequest::get('price_max'); if (!empty($max_price)) { $max_price = (double) $max_price; } else { $max_price = null; } } else { $fvalues = waRequest::get($f['code']); if ($fvalues && !isset($fvalues['min']) && !isset($fvalues['max'])) { $tmp[$fid] = $fvalues; } } } $product_skus = array(); if ($tmp) { $pf_model = new shopProductFeaturesModel(); $product_skus = $pf_model->getSkusByFeatures($product_ids, $tmp); } elseif ($min_price || $max_price) { $ps_model = new shopProductSkusModel(); $rows = $ps_model->getByField('product_id', $product_ids, true); foreach ($rows as $row) { $product_skus[$row['product_id']][] = $row; } } $default_currency = $this->getConfig()->getCurrency(true); if ($product_skus) { foreach ($product_skus as $product_id => $skus) { $currency = $products[$product_id]['currency']; usort($skus, array($this, 'sortSkus')); $k = 0; if ($min_price || $max_price) { foreach ($skus as $i => $sku) { if ($min_price) { $tmp_price = shop_currency($min_price, true, $currency, false); if ($sku['price'] < $tmp_price) { continue; } } if ($max_price) { $tmp_price = shop_currency($max_price, true, $currency, false); if ($sku['price'] > $tmp_price) { continue; } } $k = $i; break; } } $sku = $skus[$k]; if ($products[$product_id]['sku_id'] != $sku['id']) { $products[$product_id]['sku_id'] = $sku['id']; $products[$product_id]['frontend_url'] .= '?sku=' . $sku['id']; $products[$product_id]['price'] = shop_currency($sku['price'], $currency, $default_currency, false); $products[$product_id]['compare_price'] = shop_currency($sku['compare_price'], $currency, $default_currency, false); } } $this->view->assign('products', $products); } } } else { $this->setCollection($collection); } //отображение дополнительных размеров $products = $this->view->getVars('products'); $product_features_model = new shopProductFeaturesSelectableModel(); foreach ($products as &$p) { $sku_features = $product_features_model->getByProduct($p['id']); $sizes = $sku_features[3]; if (!$sizes) { $p['sizes'] = array(); continue; } $pf_names = $product_features_model->query("SELECT `id`, `value` FROM shop_feature_values_varchar where `id` IN (" . implode(',', $sizes) . ') ORDER BY `sort`;')->fetchAll(); foreach ($pf_names as $key => $val) { $sizes[$val['id']] = $val['value']; } $p['sizes'] = $pf_names; } //отображение всех картинок foreach ($products as &$p) { $images_full = shopViewHelper::images($p['id']); if (isset($images_full[$p['id']])) { $p['image_ids'] = array_keys($images_full[$p['id']]); } } $this->view->assign('products', $products); // set meta $title = $category['meta_title'] ? $category['meta_title'] : $category['name']; wa()->getResponse()->setTitle($title); wa()->getResponse()->setMeta('keywords', $category['meta_keywords']); wa()->getResponse()->setMeta('description', $category['meta_description']); /** * @event frontend_category * @return array[string]string $return[%plugin_id%] html output for category */ $this->view->assign('frontend_category', wa()->event('frontend_category', $category)); $this->setThemeTemplate('category.html'); }
public function convert($unit, $format = null) { if ($format === null) { $format = $this->format; } $value = shopDimension::getInstance()->convert($this->value, $this->type, $unit, $this->unit); return $format === false ? $value : sprintf($format, $value, $this->getUnitName($unit)); }