public function execute() { $id = $this->get('id', true); $product_model = new shopProductModel(); $data = $product_model->getById($id); if (!$data) { throw new waAPIException('invalid_param', 'Product not found', 404); } $this->response = $data; $p = new shopProduct($data); if ($p['image_id']) { $this->response['image_url'] = shopImage::getUrl(array('product_id' => $id, 'id' => $p['image_id'], 'ext' => $p['ext']), wa('shop')->getConfig()->getImageSize('default'), true); } $this->response['skus'] = array_values($p->skus); foreach ($this->response['skus'] as &$sku) { $stocks = array(); foreach ($sku['stock'] as $stock_id => $count) { $stocks[] = array('id' => $stock_id, 'count' => $count); } unset($sku['stock']); $sku['stocks'] = $stocks; } unset($sku); $this->response['categories'] = array_values($p->categories); $this->response['images'] = array_values($p->getImages('thumb', true)); $this->response['features'] = array(); foreach ($p->features as $f => $v) { if (is_array($v)) { $this->response['features'][$f] = array_values($v); } else { $this->response['features'][$f] = (string) $v; } } }
public function execute() { $product_id = $this->get('product_id', true); $product_model = new shopProductModel(); $product = $product_model->getById($product_id); if (!$product) { throw new waAPIException('invalid_param', 'Product not found', 404); } $p = new shopProduct($product); $this->response = array_values($p->getImages('thumb', true)); $this->response['_element'] = 'image'; }
public function execute() { $id = waRequest::get('id', 0, waRequest::TYPE_INT); if (!$id) { throw new waException("Unknown product"); } $product = new shopProduct($id); $sizes = $this->getConfig()->getImageSizes('system'); $images = $product->getImages($sizes); $param = waRequest::get('param', array(), waRequest::TYPE_ARRAY_INT); $image_id = !empty($param[0]) ? $param[0] : 0; if (isset($images[$image_id])) { $image = $images[$image_id]; if ($image['size']) { $image['size'] = waFiles::formatSize($image['size'], '%0.2f', 'B,KB,MB,GB'); } $this->setTemplate('ProductImage'); $images = array_values($images); array_unshift($images, null); array_push($images, null); $offset = 0; foreach ($images as $k => $img) { if ($image['id'] == $img['id']) { $offset = $k; } } $next = $images[$offset + 1]; $image['dimensions'] = shopImage::getThumbDimensions($image, $sizes['big']); $this->view->assign(array('image' => $image, 'next' => $next, 'offset' => $offset, 'original_exists' => file_exists(shopImage::getOriginalPath($image)), 'photostream' => waRequest::get('ps', array()))); } $this->view->assign(array('sizes' => $sizes, 'images' => $images, 'count' => count($images) - 2, 'product_id' => $id, 'product' => $product)); /** * @event backend_product_edit * @return array[string][string]string $return[%plugin_id%]['images'] html output */ $this->view->assign('backend_product_edit', wa()->event('backend_product_edit', $product)); }