public function execute()
 {
     $type_id = waRequest::post('type_id', null, waRequest::TYPE_ARRAY_INT);
     $product_model = new shopProductModel();
     $count = $product_model->countByField(array('type_id' => $type_id));
     $this->response = array('count_text' => $count > 0 ? '≈' . _w('%d product', '%d products', $count) : '');
 }
 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;
         }
     }
 }
Ejemplo n.º 3
0
 public function execute()
 {
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $product_model = new shopProductModel();
     $product = $product_model->getById($id);
     if (!$product) {
         throw new waException(_w("Unknown product"));
     }
     $service_id = $this->getServiceId();
     $model = $this->getModel();
     $services = $model->getServices($id);
     if ($service_id !== 0) {
         if (!empty($services)) {
             if (!$service_id || !isset($services[$service_id])) {
                 $service = reset($services);
                 $service_id = $service['id'];
             }
         }
     }
     if (!$service_id) {
         $this->assign(array('product' => $product));
         return;
     }
     $this->assign(array('service' => $this->getModel()->getProductServiceFullInfo($product['id'], $service_id), 'product' => $product, 'services' => $services, 'count' => $this->getModel()->countServices($product['id'])));
 }
Ejemplo n.º 4
0
 public function add($data, $before_id = null)
 {
     if (empty($data)) {
         return false;
     }
     $before = null;
     if ($before_id) {
         $before = $this->getById($before_id);
     }
     if (!$before) {
         $sort = $this->query("SELECT MAX(sort) AS sort FROM {$this->table}")->fetchField('sort') + 1;
     } else {
         $this->query("UPDATE {$this->table} SET sort = sort + 1 WHERE sort >= {$before['sort']}");
         $sort = (int) $before['sort'];
     }
     if (empty($data['low_count'])) {
         $data['low_count'] = shopStockModel::LOW_DEFAULT;
     }
     if (empty($data['critical_count'])) {
         $data['critical_count'] = shopStockModel::CRITICAL_DEFAULT;
     }
     $data['sort'] = $sort;
     $id = $this->insert($data);
     $product_stocks_model = new shopProductStocksModel();
     $product_stocks_model->insertZeros($id);
     $product_model = new shopProductModel();
     $product_model->correctCount();
     return $id;
 }
Ejemplo n.º 5
0
 /**
  * Delete stock with or not recounting total counter of skus
  *
  * @param int $stock_id
  * @param boolean $recount
  */
 public function deleteStock($stock_id, $recount = true)
 {
     $stock_id = (int) $stock_id;
     $stock_model = new shopStockModel();
     $stock = $stock_model->getById($stock_id);
     $stock_name = $stock ? $stock['name'] : '';
     if ($stock_id) {
         if ($recount) {
             $sql = "UPDATE `shop_product_skus` s\n                        JOIN `{$this->table}` ps ON s.id = ps.sku_id\n                        SET s.count = s.count - ps.count\n                        WHERE ps.stock_id = {$stock_id}";
             if (!$this->exec($sql)) {
                 return false;
             }
             $sql = "UPDATE `shop_product` p\n                        JOIN (\n                            SELECT product_id, SUM(count) count\n                            FROM {$this->table}\n                            WHERE stock_id = {$stock_id}\n                            GROUP BY product_id\n                        ) AS ps ON p.id = ps.product_id\n                        SET p.count = p.count - ps.count";
             if (!$this->exec($sql)) {
                 return false;
             }
             $product_model = new shopProductModel();
             $product_model->correctCount();
         }
         $log_model = new shopProductStocksLogModel();
         $log_model->updateByField(array('stock_id' => $stock_id), array('stock_id' => null, 'stock_name' => $stock_name));
         return $this->deleteByField('stock_id', $stock_id);
     }
     return false;
 }
 public function execute()
 {
     $this->setLayout(new shopFrontendLayout());
     $product_model = new shopProductModel();
     $product = $product_model->getByField('url', waRequest::param('product_url'));
     if (!$product) {
         throw new waException('Product not found', 404);
     }
     $product = new shopProduct($product);
     $this->getBreadcrumbs($product, true);
     $reviews_model = new shopProductReviewsModel();
     $reviews = $reviews_model->getFullTree($product['id'], 0, null, 'datetime DESC', array('escape' => true));
     $config = wa()->getConfig();
     $this->view->assign(array('product' => $product, 'reviews' => $reviews, 'reviews_count' => $reviews_model->count($product['id']), 'reply_allowed' => true, 'auth_adapters' => $adapters = wa()->getAuthAdapters(), 'request_captcha' => $config->getGeneralSettings('require_captcha'), 'require_authorization' => $config->getGeneralSettings('require_authorization')));
     $storage = wa()->getStorage();
     $current_auth = $storage->read('auth_user_data');
     $current_auth_source = $current_auth ? $current_auth['source'] : shopProductReviewsModel::AUTH_GUEST;
     $this->view->assign('current_auth_source', $current_auth_source);
     $this->view->assign('current_auth', $current_auth, true);
     /**
      * @event frontend_product
      * @param shopProduct $product
      * @return array[string][string]string $return[%plugin_id%]['menu'] html output
      * @return array[string][string]string $return[%plugin_id%]['cart'] html output
      * @return array[string][string]string $return[%plugin_id%]['block_aux'] html output
      * @return array[string][string]string $return[%plugin_id%]['block'] html output
      */
     $this->view->assign('frontend_product', wa()->event('frontend_product', $product, array('menu', 'cart', 'block_aux', 'block')));
     $this->setThemeTemplate('reviews.html');
 }
Ejemplo n.º 7
0
 public static function prepareSkus($skus = array(), $contact_id = null, $currency = null)
 {
     $app_settings_model = new waAppSettingsModel();
     if ($app_settings_model->get(self::$plugin_id, 'status') && shopPrice::getDomainSetting('status')) {
         $category_ids = self::getUserCategoryId($contact_id);
         $domain_hash = shopPrice::getRouteHash();
         $params = array('domain_hash' => $domain_hash, 'category_id' => $category_ids);
         $price_model = new shopPricePluginModel();
         $prices = $price_model->getPriceByParams($params, true);
         if ($prices) {
             foreach ($skus as &$sku) {
                 foreach ($prices as $price) {
                     $price_field = "price_plugin_{$price['id']}";
                     if (!empty($sku[$price_field]) && $sku[$price_field] > 0) {
                         //if (!empty($sku['unconverted_currency']) && !empty($sku['currency'])) {
                         //    $sku['price'] = shop_currency($sku[$price_field], $sku['unconverted_currency'], $sku['currency'], false);
                         //} else {
                         if (!$currency) {
                             $sku['price'] = $sku[$price_field];
                         } else {
                             $product_model = new shopProductModel();
                             $product = $product_model->getById($sku['product_id']);
                             $sku['price'] = shop_currency($sku[$price_field], $product['currency'], $currency, false);
                         }
                         //}
                         break;
                     }
                 }
             }
             unset($sku);
         }
     }
     return $skus;
 }
Ejemplo n.º 8
0
 /**
  * Amount of affiliation points given order worths.
  * @param array|int $order_or_id
  * @param float $credit_rate
  * @return float
  */
 public static function calculateBonus($order_or_id, $credit_rate = null)
 {
     if (!self::isEnabled()) {
         return 0;
     }
     if ($credit_rate === null) {
         $credit_rate = wa()->getSetting('affiliate_credit_rate', 0, 'shop');
     }
     if (!$credit_rate) {
         return 0;
     }
     if (wa_is_int($order_or_id)) {
         $om = new shopOrderModel();
         $order = $om->getOrder($order_or_id);
     } else {
         $order = $order_or_id;
     }
     // Convert order total from order currency to default currency
     $curm = new shopCurrencyModel();
     $order_currency = isset($order['currency']) ? $order['currency'] : null;
     $def_cur = wa('shop')->getConfig()->getCurrency(true);
     $affiliatable_total = $curm->convert($order['total'] - ifset($order['shipping'], 0), ifempty($order_currency, $def_cur), $def_cur);
     $product_types = wa()->getSetting('affiliate_product_types', '', 'shop');
     if (!empty($product_types)) {
         //
         // When affiliation program is enabled for certain product types only,
         // we need to calculate total afiliatable amount from order items.
         //
         $product_types = array_fill_keys(explode(',', $product_types), true);
         // Make sure order data contains items
         if (empty($order['items']) && !empty($order['id'])) {
             $oim = new shopOrderItemsModel();
             $order['items'] = $oim->getItems($order['id']);
         }
         if (empty($order['items']) || !is_array($order['items'])) {
             return 0;
         }
         // Fetch product info
         $product_ids = array();
         foreach ($order['items'] as $i) {
             $product_ids[$i['product_id']] = true;
         }
         $pm = new shopProductModel();
         $products = $pm->getById(array_keys($product_ids));
         // Calculate total value of affiliatable order items
         $items_total = 0;
         foreach ($order['items'] as $i) {
             $p = $products[$i['product_id']];
             $type_id = $p['type_id'];
             if ($i['type'] == 'product' && $type_id && !empty($product_types[$type_id])) {
                 $items_total += $curm->convert($i['price'] * $i['quantity'], ifempty($p['currency'], $def_cur), $def_cur);
             }
         }
         if ($affiliatable_total > $items_total) {
             $affiliatable_total = $items_total;
         }
     }
     return $affiliatable_total / $credit_rate;
 }
 protected function save(waRequestFile $file)
 {
     $product_id = waRequest::post('product_id', null, waRequest::TYPE_INT);
     $product_model = new shopProductModel();
     if (!$product_model->checkRights($product_id)) {
         throw new waException(_w("Access denied"));
     }
     // check image
     if (!($image = $file->waImage())) {
         throw new waException('Incorrect image');
     }
     $image_changed = false;
     /**
      * Extend upload proccess
      * Make extra workup
      * @event image_upload
      */
     $event = wa()->event('image_upload', $image);
     if ($event) {
         foreach ($event as $plugin_id => $result) {
             if ($result) {
                 $image_changed = true;
             }
         }
     }
     if (!$this->model) {
         $this->model = new shopProductImagesModel();
     }
     $data = array('product_id' => $product_id, 'upload_datetime' => date('Y-m-d H:i:s'), 'width' => $image->width, 'height' => $image->height, 'size' => $file->size, 'original_filename' => basename($file->name), 'ext' => $file->extension);
     $image_id = $data['id'] = $this->model->add($data);
     if (!$image_id) {
         throw new waException("Database error");
     }
     /**
      * @var shopConfig $config
      */
     $config = $this->getConfig();
     $image_path = shopImage::getPath($data);
     if (file_exists($image_path) && !is_writable($image_path) || !file_exists($image_path) && !waFiles::create($image_path)) {
         $this->model->deleteById($image_id);
         throw new waException(sprintf("The insufficient file write permissions for the %s folder.", substr($image_path, strlen($config->getRootPath()))));
     }
     if ($image_changed) {
         $image->save($image_path);
         // save original
         $original_file = shopImage::getOriginalPath($data);
         if ($config->getOption('image_save_original') && $original_file) {
             $file->moveTo($original_file);
         }
     } else {
         $file->moveTo($image_path);
     }
     unset($image);
     // free variable
     shopImage::generateThumbs($data, $config->getImageSizes());
     return array('id' => $image_id, 'name' => $file->name, 'type' => $file->type, 'size' => $file->size, 'url_thumb' => shopImage::getUrl($data, $config->getImageSize('thumb')), 'url_crop' => shopImage::getUrl($data, $config->getImageSize('crop')), 'url_crop_small' => shopImage::getUrl($data, $config->getImageSize('crop_small')), 'description' => '');
 }
 public function getProduct()
 {
     $product_model = new shopProductModel();
     $product = $product_model->getByField('url', waRequest::param('product_url'));
     if (!$product) {
         throw new waException('Product not found', 404);
     }
     return $product;
 }
 public function getProduct($product_id)
 {
     if ($this->product === null) {
         $this->product = $this->product_model->getById($product_id);
         if (!$this->product) {
             throw new waException(_w("Unknown product"), 404);
         }
     }
     return $this->product;
 }
Ejemplo n.º 12
0
 protected function getProduct($id)
 {
     $product_model = new shopProductModel();
     $product = $product_model->getById($id);
     if (!$product) {
         throw new waAPIException('invalid_param', 'Product not found', 404);
     }
     $this->checkRights($product['type_id']);
     return $product;
 }
 public function checkProductRights($product_id)
 {
     $product_model = new shopProductModel();
     $product = $product_model->getById($product_id);
     if (!$product) {
         throw new waAPIException('invalid_param', 'Product not found', 404);
     }
     if (!$this->getRights('type.all') || !$this->getRights('type.' . $product['type_id'])) {
         throw new waAPIException('access_denied', 500);
     }
     return true;
 }
 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);
     }
     $product_pages_model = new shopProductPagesModel();
     $this->response = $product_pages_model->getByProductId($product_id);
     $this->response['_element'] = 'page';
 }
 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';
 }
Ejemplo n.º 16
0
 public function execute()
 {
     // get id of product and check existing
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $product_model = new shopProductModel();
     $product = $product_model->getById($id);
     if (!$product) {
         throw new waException(_w("Unkown product"));
     }
     $this->product_id = $id;
     parent::execute();
 }
Ejemplo n.º 17
0
 public function execute()
 {
     $product_id = waRequest::get('product_id', null, waRequest::TYPE_INT);
     $product_model = new shopProductModel();
     $product = $product_model->getById($product_id);
     if (!$product) {
         throw new waException(_w("Unknown product"), 404);
     }
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $page = $this->getPage($id);
     $url = rtrim(wa()->getRouteUrl('/frontend/productPage', array('product_url' => $product['url'], 'page_url' => ''), true), '/');
     $this->view->assign(array('url' => $url, 'preview_hash' => $this->getPreviewHash(), 'page' => $page, 'lang' => substr(wa()->getLocale(), 0, 2), 'product_id' => $product_id));
 }
 public function execute()
 {
     $sku_id = waRequest::post('sku_id', 0, waRequest::TYPE_INT);
     $src_stock = waRequest::post('src_stock', 0, waRequest::TYPE_INT);
     $dst_stock = waRequest::post('dst_stock', 0, waRequest::TYPE_INT);
     $count = waRequest::post('count', 0, waRequest::TYPE_INT);
     if ($src_stock == $dst_stock || !$src_stock || !$dst_stock || !$count) {
         $this->errors[] = _w("Error when transfer");
         return;
     }
     $product_skus_model = new shopProductSkusModel();
     shopProductStocksLogModel::setContext(shopProductStocksLogModel::TYPE_STOCK);
     if (!$product_skus_model->transfer($sku_id, $count, $src_stock, $dst_stock)) {
         $this->errors[] = _w("Error when transfer");
         return;
     }
     shopProductStocksLogModel::clearContext();
     $sku = $product_skus_model->getById($sku_id);
     /*
     $product_stocks_model = new shopProductStocksModel();
     $data = $product_stocks_model->getStocksOfProduct($sku['product_id'], array($src_stock, $dst_stock), 'sku.count DESC');
     
     foreach ($data as &$stock) {
         foreach ($stock as &$stock_sku) {
             $stock_sku['icon'] = shopHelper::getStockCountIcon($stock_sku['count']);
         }
     }
     unset($stock, $stock_sku);
     */
     $stock_skus = array();
     $product_model = new shopProductModel();
     $data = $product_model->getProductStocksByProductId($sku['product_id']);
     if (isset($data[$sku['product_id']])) {
         $data = $data[$sku['product_id']];
         if (isset($data['stocks'][$src_stock])) {
             $stock_skus[$src_stock] = array();
             foreach ($data['stocks'][$src_stock] as $stock_sku) {
                 $stock_sku['icon'] = shopHelper::getStockCountIcon($stock_sku['count'], $src_stock);
                 $stock_skus[$src_stock][] = $stock_sku;
             }
         }
         if (isset($data['stocks'][$dst_stock])) {
             $stock_skus[$dst_stock] = array();
             foreach ($data['stocks'][$dst_stock] as $stock_sku) {
                 $stock_sku['icon'] = shopHelper::getStockCountIcon($stock_sku['count'], $dst_stock);
                 $stock_skus[$dst_stock][] = $stock_sku;
             }
         }
     }
     $this->response = array('stocks' => $stock_skus ? $stock_skus : new stdClass(), 'product_id' => $sku['product_id']);
 }
 public function execute()
 {
     $product_model = new shopProductModel();
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $product = $product_model->getById($id);
     if (!$product) {
         $this->errors[] = _w("Unknown product");
         return;
     }
     if (!$product_model->checkRights($product)) {
         throw new waException(_w("Access denied"));
     }
     $product_model->updateById($id, array('badge' => null));
 }
 public function getServices($product_id, $sku_id)
 {
     $product_model = new shopProductModel();
     $product = $product_model->getById($product_id);
     $type_service_model = new shopTypeServicesModel();
     $service_ids = $type_service_model->getServiceIds($product['type_id']);
     $sql = "SELECT v.*, ps.price p_price, ps.status, ps.sku_id, s.currency FROM shop_service_variants v\n                LEFT JOIN shop_product_services ps ON v.id = ps.service_variant_id AND ps.product_id = i:product_id\n                JOIN shop_service s ON v.service_id = s.id\n                WHERE " . ($service_ids ? "v.service_id IN (i:service_ids) OR " : '') . "\n                ps.product_id = i:product_id OR ps.sku_id = i:sku_id\n                ORDER BY ps.sku_id";
     $product_services_model = new shopProductServicesModel();
     $rows = $product_services_model->query($sql, array('service_ids' => $service_ids, 'product_id' => $product_id, 'sku_id' => $sku_id))->fetchAll();
     $services = array();
     foreach ($rows as $row) {
         $services[$row['service_id']][$row['id']] = array('name' => $row['name'], 'price' => $row['p_price'] ? $row['p_price'] : $row['price'], 'currency' => $row['currency']);
     }
     return $services;
 }
Ejemplo n.º 21
0
 public function execute()
 {
     $id = $this->post('id', true);
     if (!is_array($id)) {
         if (strpos($id, ',') !== false) {
             $id = array_map('intval', explode(',', $id));
         } else {
             $id = array($id);
         }
     }
     $product_model = new shopProductModel();
     if ($product_model->delete($id)) {
         $this->response = true;
     } else {
         throw new waAPIException('access_denied', 403);
     }
 }
Ejemplo n.º 22
0
 public function execute()
 {
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $product_model = new shopProductModel();
     $product = $product_model->getById($id);
     if (!$product) {
         throw new waException(_w("Unkown product"));
     }
     $offset = waRequest::get('offset', 0, waRequest::TYPE_INT);
     $total_count = waRequest::get('total_count', null, waRequest::TYPE_INT);
     $lazy = waRequest::get('lazy');
     $order = waRequest::get('order', 'default', waRequest::TYPE_STRING_TRIM);
     $order = isset($this->orders[$order]) ? $order : 'default';
     $product_reviews_model = new shopProductReviewsModel();
     $reviews = $product_reviews_model->getFullTree($id, $offset, $this->getConfig()->getOption('reviews_per_page_product'), $this->orders[$order], array('is_new' => true));
     $this->view->assign(array('product' => $product, 'reviews' => $reviews, 'offset' => $offset, 'total_count' => $total_count ? $total_count : $product_reviews_model->count($id), 'reply_allowed' => true, 'lazy' => $lazy, 'current_author' => shopProductReviewsModel::getAuthorInfo(wa()->getUser()->getId()), 'count' => count($reviews), 'id' => $id, 'order' => $order, 'sidebar_counters' => array('new' => $product_reviews_model->countNew())));
 }
Ejemplo n.º 23
0
 /**
  * Verifies current user's access rights to product by its type id.
  *
  * @throws waException
  * @return boolean
  */
 public function checkRights()
 {
     if (isset($this->data['type_id'])) {
         return $this->model->checkRights($this->data);
     } else {
         return $this->model->checkRights($this->getId());
     }
 }
 public function execute()
 {
     $product_id = $this->get('product_id');
     $product_model = new shopProductModel();
     $product = $product_model->getById($product_id);
     if (!$product) {
         throw new waAPIException('invalid_param', 'Product not found', 404);
     }
     $skus_model = new shopProductSkusModel();
     $skus = $skus_model->getData(new shopProduct($product));
     foreach ($skus as &$sku) {
         $sku['currency'] = $product['currency'];
         $sku['primary_price'] = (double) $sku['primary_price'];
     }
     unset($sku);
     $this->response = array_values($skus);
     $this->response['_element'] = 'sku';
 }
 public function execute()
 {
     $id = waRequest::post('id', 0, waRequest::TYPE_INT);
     if (!$id) {
         throw new waException(_w("Unknown image"));
     }
     $product_images_model = new shopProductImagesModel();
     $image = $product_images_model->getById($id);
     if (!$image) {
         throw new waException(_w("Unknown image"));
     }
     // check rights
     $product_model = new shopProductModel();
     if (!$product_model->checkRights($image['product_id'])) {
         throw new waException(_w("Access denied"));
     }
     $product_images_model->updateById($id, $this->getData());
 }
 public function execute()
 {
     $id = waRequest::post('id', null, waRequest::TYPE_INT);
     if (!$id) {
         throw new waException(_w("Unknown page"));
     }
     $product_pages_model = new shopProductPagesModel();
     $page = $product_pages_model->getById($id);
     if (!$page) {
         throw new waException(_w("Unknown page"));
     }
     // check rights
     $product_model = new shopProductModel();
     if (!$product_model->checkRights($page['product_id'])) {
         throw new waException(_w("Access denied"));
     }
     $product_pages_model->delete($id);
 }
 public static function getMapFields($flat = false, $extra_fields = false)
 {
     $fields = array('product' => array('name' => _w('Product name'), 'currency' => _w('Currency'), 'summary' => _w('Summary'), 'description' => _w('Description'), 'badge' => _w('Badge'), 'status' => _w('Status'), 'type_name' => _w('Product type'), 'tags' => _w('Tags'), 'tax_name' => _w('Taxable'), 'meta_title' => _w('Title'), 'meta_keywords' => _w('META Keyword'), 'meta_description' => _w('META Description'), 'url' => _w('Storefront link'), 'images' => _w('Product images')), 'sku' => array('skus:-1:name' => _w('SKU name'), 'skus:-1:sku' => _w('SKU code'), 'skus:-1:price' => _w('Price'), 'skus:-1:available' => _w('Available for purchase'), 'skus:-1:compare_price' => _w('Compare at price'), 'skus:-1:purchase_price' => _w('Purchase price'), 'skus:-1:stock:0' => _w('In stock')));
     if ($extra_fields) {
         $product_model = new shopProductModel();
         $sku_model = new shopProductSkusModel();
         $meta_fields = array('product' => $product_model->getMetadata(), 'sku' => $sku_model->getMetadata());
         $black_list = array('id', "contact_id", "create_datetime", "edit_datetime", "type_id", "image_id", "tax_id", "cross_selling", "upselling", "total_sales", "sku_type", "sku_count", 'sku_id', 'ext', 'price', 'compare_price', 'min_price', 'max_price', 'count', 'rating_count', 'category_id', 'base_price_selectable', 'rating');
         $white_list = array('id_1c' => '1C');
         foreach ($meta_fields['product'] as $field => $info) {
             if (!in_array($field, $black_list)) {
                 $name = ifset($white_list[$field], $field);
                 if (!empty($meta_fields['sku'][$field])) {
                     if (!isset($fields['sku']['skus:-1:' . $field])) {
                         $fields['sku']['skus:-1:' . $field] = $name;
                     }
                 } else {
                     if (!isset($fields['product'][$field])) {
                         $fields['product'][$field] = $name;
                     }
                 }
             }
         }
     }
     $stock_model = new shopStockModel();
     if ($stocks = $stock_model->getAll('id')) {
         foreach ($stocks as $stock_id => $stock) {
             $fields['sku']['skus:-1:stock:' . $stock_id] = _w('In stock') . ' @' . $stock['name'];
         }
     }
     if ($flat) {
         $fields_ = $fields;
         $fields = array();
         $flat_order = array('product:name', 'sku:skus:-1:name', 'sku:skus:-1:sku', 'product:currency');
         foreach ($flat_order as $field) {
             list($type, $field) = explode(':', $field, 2);
             $fields[$field] = $fields_[$type][$field];
             unset($fields_[$type][$field]);
         }
         $fields += $fields_['sku'];
         $fields += $fields_['product'];
     }
     return $fields;
 }
 public function execute()
 {
     $product_model = new shopProductModel();
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     $product = $product_model->getById($id);
     if (!$product) {
         throw new waException(_w("Unknown product"));
     }
     if (!$product_model->checkRights($product)) {
         throw new waException(_w("Access denied"));
     }
     $code = waRequest::post('code', null, waRequest::TYPE_STRING_TRIM);
     if (!$code) {
         throw new waException(_w("Empty code"));
     }
     $product_model->updateById($id, array('badge' => $code));
     $badges = shopProductModel::badges();
     $this->response = isset($badges[$code]) ? $badges[$code]['code'] : $code;
 }
 public function execute()
 {
     $this->setLayout(new shopFrontendLayout());
     $product_model = new shopProductModel();
     $product = $product_model->getByField('url', waRequest::param('product_url'));
     if (!$product) {
         throw new waException('Product not found', 404);
     }
     $product = new shopProduct($product);
     $this->view->assign('product', $product);
     $this->getBreadcrumbs($product, true);
     $page_model = new shopProductPagesModel();
     $page = $page_model->getByField(array('product_id' => $product['id'], 'url' => waRequest::param('page_url')));
     if (!$page['status']) {
         $hash = $this->appSettings('preview_hash');
         if (!$hash || md5($hash) != waRequest::get('preview')) {
             throw new waException('Page not found', 404);
         }
     }
     if (!$page) {
         throw new waException('Page not found', 404);
     }
     if (!$page['title']) {
         $page['title'] = $page['name'];
     }
     // interpret smarty code
     $page['content'] = $this->view->fetch('string:' . $page['content']);
     $this->view->assign('page', $page);
     $this->view->assign('reviews_total_count', $this->getReviewsTotalCount($product['id']));
     $this->getResponse()->setTitle($product['name'] . ' - ' . $page['title']);
     $this->getResponse()->setMeta(array('keywords' => isset($page['keywords']) ? $page['keywords'] : '', 'description' => isset($page['description']) ? $page['description'] : ''));
     /**
      * @event frontend_product
      * @param shopProduct $product
      * @return array[string][string]string $return[%plugin_id%]['menu'] html output
      * @return array[string][string]string $return[%plugin_id%]['cart'] html output
      * @return array[string][string]string $return[%plugin_id%]['block_aux'] html output
      * @return array[string][string]string $return[%plugin_id%]['block'] html output
      */
     $this->view->assign('frontend_product', wa()->event('frontend_product', $product, array('menu', 'cart', 'block_aux', 'block')));
     $this->setThemeTemplate('product.page.html');
 }
 public function execute()
 {
     $id = waRequest::get('id', null, waRequest::TYPE_INT);
     if (!$id) {
         throw new waException(_w("Unknown image"));
     }
     $product_images_model = new shopProductImagesModel();
     $image = $product_images_model->getById($id);
     if (!$image) {
         throw new waException(_w("Unknown image"));
     }
     $product_model = new shopProductModel();
     if (!$product_model->checkRights($image['product_id'])) {
         throw new waException(_w("Access denied"));
     }
     if (!$product_images_model->delete($id)) {
         throw new waException(_w("Coudn't delete image"));
     }
     $this->response['id'] = $id;
 }