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');
 }
 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 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()
 {
     if (waRequest::param('url_type') == 2) {
         $product_model = new shopProductModel();
         if (waRequest::param('category_url')) {
             $category_model = new shopCategoryModel();
             $c = $category_model->getByField('full_url', waRequest::param('category_url'));
             if ($c) {
                 $product = $product_model->getByUrl(waRequest::param('product_url'), $c['id']);
                 if ($product && $product['category_id'] != $c['id']) {
                     $c = $category_model->getById($product['category_id']);
                     if ($c) {
                         $this->redirect(wa()->getRouteUrl('shop/frontend/product', array('category_url' => $c['full_url'], 'product_url' => $product['url'])));
                     } else {
                         $product = null;
                     }
                 }
             } else {
                 $product = null;
             }
         } else {
             $product = $product_model->getByField('url', waRequest::param('product_url'));
         }
         if (!$product) {
             // try find page
             $url = waRequest::param('category_url');
             $url_parts = explode('/', $url);
             waRequest::setParam('page_url', waRequest::param('product_url'));
             waRequest::setParam('product_url', end($url_parts));
             $this->executeAction(new shopFrontendProductPageAction());
         } else {
             $this->executeAction(new shopFrontendProductAction($product));
         }
     } else {
         $this->executeAction(new shopFrontendProductAction());
     }
 }
Esempio n. 5
0
 public function execute()
 {
     $offset = waRequest::get('offset', 0, waRequest::TYPE_INT);
     $total_count = waRequest::get('total_count', null, waRequest::TYPE_INT);
     $lazy = waRequest::get('lazy', false, waRequest::TYPE_INT);
     $product_reivews_model = new shopProductReviewsModel();
     $reviews_per_page = $this->getConfig()->getOption('reviews_per_page_total');
     /*
     $reviews = $product_reivews_model->getList(
         $offset,
         $reviews_per_page,
         array('is_new' => true)
     );
     */
     $reviews = $product_reivews_model->getList('*,is_new,contact,product', array('offset' => $offset, 'limit' => $reviews_per_page));
     // TODO: move to model
     $product_ids = array();
     foreach ($reviews as $review) {
         $product_ids[] = $review['product_id'];
     }
     $product_ids = array_unique($product_ids);
     $product_model = new shopProductModel();
     $products = $product_model->getByField('id', $product_ids, 'id');
     $image_size = wa()->getConfig()->getImageSize('crop_small');
     foreach ($reviews as &$review) {
         if (isset($products[$review['product_id']])) {
             $product = $products[$review['product_id']];
             $review['product_name'] = $product['name'];
             if ($product['image_id']) {
                 $review['product_url_crop_small'] = shopImage::getUrl(array('id' => $product['image_id'], 'product_id' => $product['id'], 'ext' => $product['ext']), $image_size);
             } else {
                 $review['product_url_crop_small'] = null;
             }
         }
     }
     $this->view->assign(array('total_count' => $total_count ? $total_count : $product_reivews_model->countAll(), 'count' => count($reviews), 'offset' => $offset, 'reviews' => $reviews, 'current_author' => shopProductReviewsModel::getAuthorInfo(wa()->getUser()->getId()), 'reply_allowed' => true, 'lazy' => $lazy, 'sidebar_counters' => array('new' => $product_reivews_model->countNew(!$offset))));
 }
 private function workupList(&$data, $fields, $escape)
 {
     $extract_contact_info = false;
     foreach (explode(',', $fields) as $field) {
         if ($field == 'contact') {
             $contact_ids = array();
             foreach ($data as $item) {
                 if ($item['contact_id']) {
                     $contact_ids[] = $item['contact_id'];
                 }
             }
             $contact_ids = array_unique($contact_ids);
             $contacts = self::getAuthorInfo($contact_ids);
             foreach ($data as &$item) {
                 $author = array('name' => $item['name'], 'email' => $item['email'], 'site' => $item['site']);
                 $item['author'] = array_merge($author, isset($contacts[$item['contact_id']]) ? $contacts[$item['contact_id']] : array());
                 if ($escape) {
                     $item['author']['name'] = htmlspecialchars($item['author']['name']);
                 }
             }
             unset($item);
         }
         if ($field == 'is_new') {
             $this->checkForNew($data);
         }
         if ($field == 'product') {
             $product_ids = array();
             foreach ($data as $item) {
                 $product_ids[] = $item['product_id'];
             }
             $product_ids = array_unique($product_ids);
             $product_model = new shopProductModel();
             $products = $product_model->getByField('id', $product_ids, 'id');
             $image_size = wa()->getConfig()->getImageSize('crop_small');
             foreach ($data as &$item) {
                 if (isset($products[$item['product_id']])) {
                     $product = $products[$item['product_id']];
                     $item['product_name'] = $product['name'];
                     if ($product['image_id']) {
                         $item['product_url_crop_small'] = shopImage::getUrl(array('id' => $product['image_id'], 'product_id' => $product['id'], 'ext' => $product['ext']), $image_size);
                     } else {
                         $item['product_url_crop_small'] = null;
                     }
                 }
             }
         }
     }
     foreach ($data as &$item) {
         // recursive workuping
         if (!empty($item['comments'])) {
             $this->extendItems($item['comments'], $options);
         }
     }
     unset($item);
 }
 /**
  *
  * @param array $data
  * @return shopProduct
  */
 private function findProduct(&$data)
 {
     static $currencies;
     static $model;
     static $sku_model;
     /**
      * @var shopTypeFeaturesModel $type_features_model
      */
     static $type_features_model;
     if (empty($model)) {
         $model = new shopProductModel();
     }
     if (empty($currencies)) {
         $currencies = array();
         $config = wa()->getConfig();
         /**
          * @var shopConfig $config
          */
         $c = $config->getCurrency();
         $currencies[$c] = $c;
         foreach ($config->getCurrencies() as $row) {
             $currencies[$row['code']] = $row['code'];
         }
     }
     if (!empty($data['skus'][-1]['stock'])) {
         $per_stock = false;
         $stock =& $data['skus'][-1]['stock'];
         foreach ($stock as $id => &$count) {
             if ($count === '') {
                 $count = null;
             } else {
                 $count = intval($count);
                 if ($id) {
                     $per_stock = true;
                 }
             }
         }
         unset($count);
         if ($per_stock) {
             if (isset($stock[0])) {
                 unset($stock[0]);
             }
         } else {
             $count = ifset($stock[0]);
             $stock = array(0 => $count);
         }
         unset($stock);
     }
     $stack = ifset($this->data['map'][self::STAGE_CATEGORY], array());
     $category_id = end($stack);
     if (!$category_id) {
         $category_id = null;
     }
     $primary = $this->data['primary'];
     $fields = false;
     if (empty($primary)) {
         $keys = explode(':', $this->data['secondary']);
         if (empty($sku_model)) {
             $sku_model = new shopProductSkusModel();
         }
         $sku_fields = array(end($keys) => self::getData($data, $keys));
         //hack for empty SKU code ???
         if (false && reset($sku_fields) === '' && $this->data['extra_secondary']) {
             $extra_keys = explode(':', $this->data['extra_secondary']);
             $sku_fields[end($extra_keys)] = self::getData($data, $this->data['extra_secondary']);
         }
         if ($sku = $sku_model->getByField($sku_fields)) {
             $fields = array('category_id' => $category_id, 'id' => $sku['product_id']);
         }
     } elseif (!empty($primary)) {
         $fields = array('category_id' => $category_id, $primary => ifset($data[$primary], ''));
     }
     if ($fields && $this->data['ignore_category']) {
         unset($fields['category_id']);
     }
     $key = 'p';
     if ($fields && ($current_data = $model->getByField($fields))) {
         $product = new shopProduct($current_data['id']);
         $data['type_id'] = ifempty($current_data['type_id'], $this->data['type_id']);
         if (!empty($current_data['tax_id'])) {
             $data['tax_id'] = $current_data['tax_id'];
         }
         if (isset($data['currency']) && !isset($currencies[$data['currency']])) {
             $this->data['processed_count'][self::STAGE_PRODUCT]['currency']++;
             $data['currency'] = reset($currencies);
         }
         if (!empty($data['skus'])) {
             $data['sku_id'] = ifempty($current_data['sku_id'], -1);
         }
         foreach ($product->skus as $sku_id => $current_sku) {
             if (empty($data['skus'][$sku_id])) {
                 if (!count($current_sku['stock']) && $current_sku['count'] !== null) {
                     $current_sku['stock'][0] = $current_sku['count'];
                 }
                 $data['skus'][$sku_id] = $current_sku;
             }
         }
         $key .= ':u:' . $product->getId();
     } else {
         $product = new shopProduct();
         if ($category_id) {
             $data['categories'] = array($category_id);
         }
         $data['currency'] = ifempty($data['currency'], reset($currencies));
         if (!isset($currencies[$data['currency']])) {
             $this->data['processed_count'][self::STAGE_PRODUCT]['currency']++;
             $data['currency'] = reset($currencies);
         }
         if (!empty($data['skus'])) {
             $sku = reset($data['skus']);
             $data['sku_id'] = key($data['skus']);
             if (!isset($sku['available'])) {
                 $sku['available'] = true;
                 $data['skus'][$data['sku_id']] = $sku;
             }
         }
         $key .= ':i:' . $this->getKey($fields);
     }
     if (!empty($data['features'])) {
         foreach ($data['features'] as $feature => &$values) {
             if (is_array($values)) {
             } elseif (preg_match('/^<\\{(.*)\\}>$/', $values, $matches)) {
                 if (!isset($data['features_selectable'])) {
                     $data['features_selectable'] = array();
                 }
                 if ($values = explode(',', $matches[1])) {
                     foreach ($values as &$value) {
                         if (preg_match('@^(.+)=([\\+\\-]?(\\d+|\\.\\d+|\\d\\.\\d))$@', $value, $matches)) {
                             $value = array('value' => trim($matches[1]), 'price' => $matches[2]);
                         } else {
                             $value = array('value' => trim($value));
                         }
                         unset($value);
                     }
                     $data['features_selectable'][$feature] = array('values' => $values);
                     if (!empty($this->data['virtual_sku_stock']) && isset($data['skus'][-1]['stock'])) {
                         $stock = $data['skus'][-1]['stock'];
                         switch ($this->data['virtual_sku_stock']) {
                             case 'distribute':
                                 if (is_array($stock)) {
                                     foreach ($stock as &$stock_item) {
                                         $stock_item = $stock_item / count($values);
                                         unset($stock_item);
                                     }
                                 } else {
                                     $stock = $stock / count($values);
                                 }
                                 $data['features_selectable'][$feature]['stock'] = $stock;
                                 break;
                             case 'set':
                                 $data['features_selectable'][$feature]['stock'] = $stock;
                                 break;
                         }
                     }
                     $product->sku_type = shopProductModel::SKU_TYPE_SELECTABLE;
                     if (isset($data['skus'][-1])) {
                         if (!isset($data['base_price_selectable'])) {
                             $data['base_price_selectable'] = ifset($data['skus'][-1]['price']);
                         }
                         if (!isset($data['purchase_price_selectable'])) {
                             $data['purchase_price_selectable'] = ifset($data['skus'][-1]['purchase_price']);
                         }
                         if (!isset($data['compare_price_selectable'])) {
                             $data['compare_price_selectable'] = ifset($data['skus'][-1]['compare_price']);
                         }
                     }
                     unset($data['skus']);
                 }
                 unset($data['features'][$feature]);
             } elseif (preg_match('/^\\{(.*)\\}$/', $values, $matches)) {
                 $values = explode(',', $matches[1]);
             }
         }
         unset($values);
     }
     $this->findTax($data);
     $access = $this->findType($data);
     if ($access) {
         $access = !$product->type_id || in_array($product->type_id, $this->data['types']);
     }
     if ($access) {
         $product->__hash = $key;
         foreach ($this->data['new_features'] as $code => &$feature) {
             if (isset($data['features'][$code]) || isset($data['features_selectable'][$code])) {
                 if ($data['type_id'] && !in_array($data['type_id'], $feature['types'])) {
                     if (empty($type_features_model)) {
                         $type_features_model = new shopTypeFeaturesModel();
                     }
                     $type_features_model->updateByFeature($feature['id'], array($data['type_id']), false);
                     $feature['types'][] = $data['type_id'];
                 }
             }
             unset($feature);
         }
     }
     return $access ? $product : null;
 }
Esempio n. 8
0
 public function getByCode($code, $full_info = false, $hierarchy = true)
 {
     if (!$code) {
         return array();
     }
     $sql = "SELECT * FROM " . $this->table . " WHERE code = s:0 ORDER BY parent_id";
     $items = $this->query($sql, $code)->fetchAll('id');
     if ($full_info) {
         $product_ids = $sku_ids = $service_ids = $variant_ids = array();
         foreach ($items as $item) {
             $product_ids[] = $item['product_id'];
             $sku_ids[] = $item['sku_id'];
             if ($item['type'] == 'service') {
                 $service_ids[] = $item['service_id'];
                 if ($item['service_variant_id']) {
                     $variant_ids[] = $item['service_variant_id'];
                 }
             }
         }
         $product_model = new shopProductModel();
         $products = $product_model->getByField('id', $product_ids, 'id');
         $sku_model = new shopProductSkusModel();
         $skus = $sku_model->getByField('id', $sku_ids, 'id');
         $service_model = new shopServiceModel();
         $services = $service_model->getByField('id', $service_ids, 'id');
         $service_variants_model = new shopServiceVariantsModel();
         $variants = $service_variants_model->getByField('id', $variant_ids, 'id');
         $product_services_model = new shopProductServicesModel();
         $rows = $product_services_model->getByProducts($product_ids);
         $product_services = $sku_services = array();
         foreach ($rows as $row) {
             if ($row['sku_id'] && !in_array($row['sku_id'], $sku_ids)) {
                 continue;
             }
             $service_ids[] = $row['service_id'];
             if (!$row['sku_id']) {
                 $product_services[$row['product_id']][$row['service_variant_id']] = $row;
             }
             if ($row['sku_id']) {
                 $sku_services[$row['sku_id']][$row['service_variant_id']] = $row;
             }
         }
         foreach ($items as $item_key => &$item) {
             if ($item['type'] == 'product' && isset($products[$item['product_id']])) {
                 $item['product'] = $products[$item['product_id']];
                 if (!isset($skus[$item['sku_id']])) {
                     unset($items[$item_key]);
                     continue;
                 }
                 $sku = $skus[$item['sku_id']];
                 $item['sku_code'] = $sku['sku'];
                 $item['purchase_price'] = $sku['purchase_price'];
                 $item['sku_name'] = $sku['name'];
                 $item['currency'] = $item['product']['currency'];
                 $item['price'] = $sku['price'];
                 $item['name'] = $item['product']['name'];
                 if ($item['sku_name']) {
                     $item['name'] .= ' (' . $item['sku_name'] . ')';
                 }
             } elseif ($item['type'] == 'service' && isset($services[$item['service_id']])) {
                 $item['name'] = $item['service_name'] = $services[$item['service_id']]['name'];
                 $item['currency'] = $services[$item['service_id']]['currency'];
                 $item['service'] = $services[$item['service_id']];
                 $item['variant_name'] = $variants[$item['service_variant_id']]['name'];
                 if ($item['variant_name']) {
                     $item['name'] .= ' (' . $item['variant_name'] . ')';
                 }
                 $item['price'] = $variants[$item['service_variant_id']]['price'];
                 if (isset($product_services[$item['product_id']][$item['service_variant_id']])) {
                     if ($product_services[$item['product_id']][$item['service_variant_id']]['price'] !== null) {
                         $item['price'] = $product_services[$item['product_id']][$item['service_variant_id']]['price'];
                     }
                 }
                 if (isset($sku_services[$item['sku_id']][$item['service_variant_id']])) {
                     if ($sku_services[$item['sku_id']][$item['service_variant_id']]['price'] !== null) {
                         $item['price'] = $sku_services[$item['sku_id']][$item['service_variant_id']]['price'];
                     }
                 }
                 if ($item['currency'] == '%') {
                     $p = $items[$item['parent_id']];
                     $item['price'] = $item['price'] * $p['price'] / 100;
                     $item['currency'] = $p['currency'];
                 }
             }
         }
         unset($item);
     }
     // sort
     foreach ($items as $item_id => $item) {
         if ($item['parent_id']) {
             $items[$item['parent_id']]['services'][] = $item;
             unset($items[$item_id]);
         }
     }
     if (!$hierarchy) {
         $result = array();
         foreach ($items as $item_id => $item) {
             if (isset($item['services'])) {
                 $i = $item;
                 unset($i['services']);
                 $result[$item_id] = $i;
                 foreach ($item['services'] as $s) {
                     $result[$s['id']] = $s;
                 }
             } else {
                 $result[$item_id] = $item;
             }
         }
         $items = $result;
     }
     return $items;
 }
    public function execute()
    {
        $this->setLayout(new shopFrontendLayout());
        if ($this->params) {
            $product = $this->params;
        } else {
            $product_model = new shopProductModel();
            $product = $product_model->getByField('url', waRequest::param('product_url'));
        }
        if (!$product) {
            throw new waException(_w('Product not found'), 404);
        }
        if ($types = waRequest::param('type_id')) {
            if (!in_array($product['type_id'], (array) $types)) {
                throw new waException(_w('Product not found'), 404);
            }
        }
        $is_cart = waRequest::get('cart');
        if ($is_cart) {
            $this->setLayout(null);
        }
        $product = new shopProduct($product);
        if (!$is_cart) {
            $this->getBreadcrumbs($product);
        }
        // check url
        $product['num'] = 141;
        if ($product['url'] !== urldecode(waRequest::param('product_url'))) {
            $url_params = array('product_url' => $product['url']);
            if ($product['category_id']) {
                $url_params['category_url'] = $product['category_url'];
            }
            $q = waRequest::server('QUERY_STRING');
            $this->redirect(wa()->getRouteUrl('/frontend/product', $url_params) . ($q ? '?' . $q : ''), 301);
        }
        $this->prepareProduct($product);
        $this->addCanonical();
        // get services
        $type_services_model = new shopTypeServicesModel();
        $services = $type_services_model->getServiceIds($product['type_id']);
        $service_model = new shopServiceModel();
        $product_services_model = new shopProductServicesModel();
        $services = array_merge($services, $product_services_model->getServiceIds($product['id']));
        $services = array_unique($services);
        $services = $service_model->getById($services);
        $variants_model = new shopServiceVariantsModel();
        $rows = $variants_model->getByField('service_id', array_keys($services), true);
        foreach ($rows as $row) {
            if (!$row['price']) {
                $row['price'] = $services[$row['service_id']]['price'];
            }
            $services[$row['service_id']]['variants'][$row['id']] = $row;
        }
        $rows = $product_services_model->getByField('product_id', $product['id'], true);
        $skus_services = array();
        foreach ($product['skus'] as $sku) {
            $skus_services[$sku['id']] = array();
        }
        foreach ($rows as $row) {
            if (!$row['sku_id']) {
                // remove disabled services and variantsimg
                if (!$row['status']) {
                    unset($services[$row['service_id']]['variants'][$row['service_variant_id']]);
                } elseif ($row['price'] !== null) {
                    // update price
                    $services[$row['service_id']]['variants'][$row['service_variant_id']]['price'] = $row['price'];
                }
                if ($row['status'] == shopProductServicesModel::STATUS_DEFAULT) {
                    // update default
                    $services[$row['service_id']]['variant_id'] = $row['service_variant_id'];
                }
            } else {
                if (!$row['status']) {
                    $skus_services[$row['sku_id']][$row['service_id']][$row['service_variant_id']] = false;
                } else {
                    $skus_services[$row['sku_id']][$row['service_id']][$row['service_variant_id']] = $row['price'];
                }
            }
        }
        foreach ($skus_services as $sku_id => &$sku_services) {
            $sku_price = $product['skus'][$sku_id]['price'];
            foreach ($services as $service_id => $service) {
                if (isset($sku_services[$service_id])) {
                    if ($sku_services[$service_id]) {
                        foreach ($service['variants'] as $v) {
                            if (!isset($sku_services[$service_id][$v['id']]) || $sku_services[$service_id][$v['id']] === null) {
                                $sku_services[$service_id][$v['id']] = array($v['name'], $this->getPrice($v['price'], $service['currency'], $sku_price, $product['currency']));
                            } elseif ($sku_services[$service_id][$v['id']]) {
                                $sku_services[$service_id][$v['id']] = array($v['name'], $this->getPrice($sku_services[$service_id][$v['id']], $service['currency'], $sku_price, $product['currency']));
                            }
                        }
                    }
                } else {
                    foreach ($service['variants'] as $v) {
                        $sku_services[$service_id][$v['id']] = array($v['name'], $this->getPrice($v['price'], $service['currency'], $sku_price, $product['currency']));
                    }
                }
            }
        }
        unset($sku_services);
        // disable service if all variants disabled
        foreach ($skus_services as $sku_id => $sku_services) {
            foreach ($sku_services as $service_id => $service) {
                if (is_array($service)) {
                    $disabled = true;
                    foreach ($service as $v) {
                        if ($v !== false) {
                            $disabled = false;
                            break;
                        }
                    }
                    if ($disabled) {
                        $skus_services[$sku_id][$service_id] = false;
                    }
                }
            }
        }
        foreach ($services as $s_id => &$s) {
            if (!$s['variants']) {
                unset($services[$s_id]);
                continue;
            }
            if ($s['currency'] == '%') {
                foreach ($s['variants'] as $v_id => $v) {
                    $s['variants'][$v_id]['price'] = $v['price'] * $product['skus'][$product['sku_id']]['price'] / 100;
                }
                $s['currency'] = $product['currency'];
            }
            if (count($s['variants']) == 1) {
                $v = reset($s['variants']);
                if ($v['name']) {
                    $s['name'] .= ' ' . $v['name'];
                }
                $s['variant_id'] = $v['id'];
                $s['price'] = $v['price'];
                unset($s['variants']);
                foreach ($skus_services as $sku_id => $sku_services) {
                    if (isset($sku_services[$s_id]) && isset($sku_services[$s_id][$v['id']])) {
                        $skus_services[$sku_id][$s_id] = $sku_services[$s_id][$v['id']][1];
                    }
                }
            }
        }
        unset($s);
        uasort($services, array('shopServiceModel', 'sortServices'));
        $this->view->assign('sku_services', $skus_services);
        $this->view->assign('services', $services);
        $compare = waRequest::cookie('shop_compare', array(), waRequest::TYPE_ARRAY_INT);
        $this->view->assign('compare', in_array($product['id'], $compare) ? $compare : array());
        if (!$is_cart) {
            $this->view->assign('reviews', $this->getTopReviews($product['id']));
            $this->view->assign('rates', $this->reviews_model->getProductRates($product['id']));
            $this->view->assign('reviews_total_count', $this->getReviewsTotalCount($product['id']));
            $meta_fields = $this->getMetafields($product);
            $title = $meta_fields['meta_title'] ? $meta_fields['meta_title'] : $product['name'];
            wa()->getResponse()->setTitle($title);
            wa()->getResponse()->setMeta('keywords', $meta_fields['meta_keywords']);
            wa()->getResponse()->setMeta('description', $meta_fields['meta_description']);
            $feature_codes = array_keys($product->features);
            $feature_model = new shopFeatureModel();
            $features = $feature_model->getByCode($feature_codes);
            $this->view->assign('features', $features);
        }
        $this->view->assign('currency_info', $this->getCurrencyInfo());
        /**
         * @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')));
        $sku_stocks = array();
        foreach ($product->skus as $sku) {
            $sku_stocks[$sku_id] = array($sku['count'], $sku['stock']);
        }
        $stock_model = new shopStockModel();
        $this->view->assign('stocks', $stock_model->getAll('id'));
        $duble = db_query("SELECT * FROM shop_product where id=" . $product['id']);
        $dubles = mysql_fetch_assoc($duble);
        $dubles_sku = db_query("SELECT * FROM shop_product_skus where product_id=" . $product['id'] . " and  id=" . $dubles['sku_id']);
        $dubl_sku = mysql_fetch_assoc($dubles_sku);
        $dubles_prod = db_query("SELECT * FROM shop_product_skus where product_id!=" . $product['id'] . " and  sku='" . $dubl_sku['sku'] . "' Group by product_id");
        while ($dubl_product = mysql_fetch_array($dubles_prod)) {
            $dubles_img_pr = db_query("SELECT * FROM shop_product p, shop_product_images img where p.id=" . $dubl_product['product_id'] . " and img.product_id=" . $dubl_product['product_id'] . "");
            $dubles_img = mysql_fetch_assoc($dubles_img_pr);
            if ($dubles_img['status'] != 0) {
                $koldz = substr($dubles_img['product_id'], -2, 2);
                $kolds = str_replace($koldz, '', $dubles_img['product_id']);
                if (preg_match_all("#\\d#", $kolds) < 2) {
                    $kolds = '0' . $kolds;
                }
                if ($kolds == 0) {
                    $kolds = '00';
                }
                $alt_test = db_query("SELECT * FROM shop_product_features_selectable where feature_id=12 and  product_id=" . $dubles_img['product_id'] . "");
                $alt_t = mysql_fetch_assoc($alt_test);
                $alt_value = db_query("SELECT * FROM shop_feature_values_color where id=" . $alt_t['value_id'] . "");
                $alt = mysql_fetch_assoc($alt_value);
                $dubl_p = $dubl_p . ' <a  class="duble_prod"  href="http://' . $_SERVER['HTTP_HOST'] . '/index.php/' . $dubles_img['url'] . '" >
		 
		 
		 <img alt="' . $alt['value'] . '" title="' . $alt['value'] . '"  style="width:50px" src="/wa-data/public/shop/products/' . $koldz . '/' . $kolds . '/' . $dubles_img['product_id'] . '/images/' . $dubles_img['id'] . '/' . $dubles_img['id'] . '.96x96.jpg"/></a>';
                $dubl_p2 = $dubl_p2 . '<a onclick="doubl(' . $dubles_img['product_id'] . ')" class="duble_prod" >
		 
		 
		 <img alt="' . $alt['value'] . '" title="' . $alt['value'] . '" style="width:50px" src="/wa-data/public/shop/products/' . $koldz . '/' . $kolds . '/' . $dubles_img['product_id'] . '/images/' . $dubles_img['id'] . '/' . $dubles_img['id'] . '.96x96.jpg"/></a>';
            }
            $dubl_p = $dubl_p;
            $dubl_p2 = $dubl_p2;
        }
        $this->view->assign('duble', $dubl_p);
        $this->view->assign('duble2', $dubl_p2);
        $this->view->assign('duble_list', $dubl_p);
        $product['num'] = $_GET['num'];
        $this->view->assign('numis', $_GET['num']);
        $this->setThemeTemplate($is_cart ? 'product.cart.html' : 'product.html');
    }
 public static function widget()
 {
     if (!($api_key = self::_get_app_key())) {
         return false;
     }
     $js_info_user = '';
     if ($user_id = wa()->getUser()->getId()) {
         $fields = array('first_name' => wa()->getUser()->get('firstname', 'default'), 'last_name' => wa()->getUser()->get('lastname', 'default'), 'phone' => wa()->getUser()->get('phone', 'default'), 'email' => wa()->getUser()->get('email', 'default'));
         $js_visitor_info = array();
         foreach ($fields as $key => $value) {
             if ($value) {
                 $js_visitor_info[] = $key . ": '" . str_replace("'", "\\'", $value) . "'";
             }
         }
         $js_info_user = "******" . implode(",\n", $js_visitor_info) . "},\r\n\t\t\t";
     }
     $product_model = new shopProductModel();
     $product = $product_model->getByField('url', waRequest::param('product_url'));
     $js_ready = '';
     if ($product) {
         $js_ready = "\r\n\t\t\t\tconvead('event', 'view_product', {\r\n\t\t\t\t\tproduct_id: '{$product["id"]}',\r\n\t\t\t\t\tproduct_name: '{$product["name"]}',\r\n\t\t\t\t\tproduct_url: window.location.href\r\n\t\t\t\t  });\r\n\t\t\t";
     }
     $ret = "<!-- Convead Widget -->\r\n\t\t<script>\r\n\t\twindow.ConveadSettings = {\r\n\t\t\t{$js_info_user}\r\n\t\t\tapp_key: '{$api_key}'\r\n\r\n\t\t\t/* For more information on widget configuration please see:\r\n\t\t\t   http://help.convead.ru/knowledge_base/item/25215\r\n\t\t\t*/\r\n\t\t};\r\n\r\n\t\t(function(w,d,c){w[c]=w[c]||function(){(w[c].q=w[c].q||[]).push(arguments)};var ts = (+new Date()/86400000|0)*86400;var s = d.createElement('script');s.type = 'text/javascript';s.async = true;s.src = 'https://tracker.convead.io/widgets/'+ts+'/widget-{$api_key}.js';var x = d.getElementsByTagName('script')[0];x.parentNode.insertBefore(s, x);})(window,document,'convead');\r\n\r\n{{$js_ready}}\r\n\t\t</script>\r\n\t\t<!-- /Convead Widget -->";
     return $ret;
 }