/** * Returns information about product's images. * * @param string|array $sizes Image size id or array of size ids. * Acceptable values: 'big', 'default', 'thumb', 'crop', 'crop_small'. If empty, 'crop' is assumed by default. * @param bool $absolute Whether absolute or relative image URLs must be returned. * * @see shopConfig::$image_sizes — actual image size values correspondings to size ids * * @return array Array containing sub-arrays of individual product images */ public function getImages($sizes = array(), $absolute = false) { if ($this->getId()) { $images_model = new shopProductImagesModel(); if (empty($sizes)) { $sizes = 'crop'; } return $images_model->getImages($this->getId(), $sizes, 'id', $absolute); } else { return array(); } }
private function workupProducts(&$products = array(), $escape) { // Names of fields that must be converted to float values $float = array('min_price', 'max_price', 'total_sales', 'base_price_selectable', 'rating', 'price', 'compare_price'); foreach ($products as &$p) { foreach ($float as $field) { if (isset($p[$field])) { $p[$field] = (double) $p[$field]; } } if ($this->is_frontend && $p['compare_price'] && $p['compare_price'] <= $p['price']) { $p['compare_price'] = 0; } // escape if ($escape) { $p['name'] = htmlspecialchars($p['name']); $p['url'] = htmlspecialchars($p['url']); } } unset($p); if (!empty($this->options['params'])) { $product_params_model = new shopProductParamsModel(); $rows = $product_params_model->getByField('product_id', array_keys($products), true); foreach ($rows as $row) { $products[$row['product_id']]['params'][$row['name']] = $row['value']; } } if ($this->post_fields) { $ids = array_keys($products); foreach ($this->post_fields as $table => $fields) { if ($table == '_internal') { if ($this->is_frontend && waRequest::param('url_type') == 2) { $cat_ids = array(); foreach ($products as &$p) { if (!empty($p['category_id'])) { $cat_ids[] = $p['category_id']; } } $cat_ids = array_unique($cat_ids); if ($cat_ids) { $categories = $this->getModel('category')->getById($cat_ids); foreach ($products as &$p) { if (!empty($p['category_id'])) { $p['category_url'] = $categories[$p['category_id']]['full_url']; } } } } foreach ($fields as $i => $f) { if ($f == 'images' || $f == 'image') { if ($f == 'images') { $product_images_model = new shopProductImagesModel(); $product_images = $product_images_model->getImages($ids, 'thumb', 'product_id'); foreach ($product_images as $product_id => $images) { $products[$product_id]['images'] = $images; } } elseif ($f == 'image') { $thumb_size = wa('shop')->getConfig()->getImageSize('thumb'); $big_size = wa('shop')->getConfig()->getImageSize('big'); foreach ($products as &$p) { if ($p['image_id']) { $tmp = array('id' => $p['image_id'], 'product_id' => $p['id'], 'ext' => $p['ext']); $p['image']['thumb_url'] = shopImage::getUrl($tmp, $thumb_size, isset($this->options['absolute']) ? $this->options['absolute'] : false); $p['image']['big_url'] = shopImage::getUrl($tmp, $big_size, isset($this->options['absolute']) ? $this->options['absolute'] : false); } } } } elseif ($f == 'frontend_url') { foreach ($products as &$p) { $route_params = array('product_url' => $p['url']); if (isset($p['category_url'])) { $route_params['category_url'] = $p['category_url']; } elseif (isset($this->info['hash']) && $this->info['hash'] == 'category') { if (isset($this->info['subcategories']) && $this->info['id'] != $p['category_id']) { if (isset($this->info['subcategories'][$p['category_id']])) { $route_params['category_url'] = $this->info['subcategories'][$p['category_id']]['full_url']; } } else { $route_params['category_url'] = $this->info['full_url']; } } $p['frontend_url'] = wa()->getRouteUrl('shop/frontend/product', $route_params); } unset($p); } } } } } }
public function images($product_ids, $size = array(), $absolute = false) { if (!$product_ids) { return array(); } $product_ids = array_map('intval', (array) $product_ids); $product_images_model = new shopProductImagesModel(); return $product_images_model->getImages($product_ids, $size, 'product_id', $absolute); }