Exemplo n.º 1
0
 public static function getProductsProperties($id_lang, $query_result)
 {
     $results_array = array();
     if (is_array($query_result)) {
         foreach ($query_result as $row) {
             if ($row2 = Product::getProductProperties($id_lang, $row)) {
                 if (Pack::isPack($row['id_product'])) {
                     $row2['is_pack'] = true;
                     $row2['pack_items'] = Pack::getItemTable($row['id_product'], $id_lang, true);
                     if (!$row2['pack_items']) {
                         $row2['pack_items'] = array();
                     }
                 }
                 $row['is_bestsaler'] = ProductSale::isBestsaler($row['id_product']);
                 $results_array[] = $row2;
             }
         }
     }
     return $results_array;
 }
Exemplo n.º 2
0
 /**
  * Assign template vars related to page content
  * @see FrontController::initContent()
  */
 public function initContent()
 {
     parent::initContent();
     $flag_pack = true;
     if (!$this->errors) {
         //                        if(!isset($_GET['quick_view']))
         //                            if (Pack::isPack((int)$this->product->id) && !Pack::isInStock((int)$this->product->id))
         //                        if (Pack::isPack((int)$this->product->id))
         //                            $this->product->quantity = 0;
         //                        else
         //                            $flag_pack = false;
         //                        else
         //                            $flag_pack = false;
         if (!Pack::isPack((int) $this->product->id)) {
             $flag_pack = false;
         }
         $this->product->description = $this->transformDescriptionWithImg($this->product->description);
         // Assign to the template the id of the virtual product. "0" if the product is not downloadable.
         $this->context->smarty->assign('virtual', ProductDownload::getIdFromIdProduct((int) $this->product->id));
         $this->context->smarty->assign('customizationFormTarget', Tools::safeOutput(urldecode($_SERVER['REQUEST_URI'])));
         if (Tools::isSubmit('submitCustomizedDatas')) {
             // If cart has not been saved, we need to do it so that customization fields can have an id_cart
             // We check that the cookie exists first to avoid ghost carts
             if (!$this->context->cart->id && isset($_COOKIE[$this->context->cookie->getName()])) {
                 $this->context->cart->add();
                 $this->context->cookie->id_cart = (int) $this->context->cart->id;
             }
             $this->pictureUpload();
             $this->textRecord();
             $this->formTargetFormat();
         } else {
             if (Tools::getIsset('deletePicture') && !$this->context->cart->deleteCustomizationToProduct($this->product->id, Tools::getValue('deletePicture'))) {
                 $this->errors[] = Tools::displayError('An error occurred while deleting the selected picture.');
             }
         }
         $pictures = array();
         $text_fields = array();
         if ($this->product->customizable) {
             $files = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_FILE, true);
             foreach ($files as $file) {
                 $pictures['pictures_' . $this->product->id . '_' . $file['index']] = $file['value'];
             }
             $texts = $this->context->cart->getProductCustomization($this->product->id, Product::CUSTOMIZE_TEXTFIELD, true);
             foreach ($texts as $text_field) {
                 $text_fields['textFields_' . $this->product->id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
             }
         }
         $this->context->smarty->assign(array('pictures' => $pictures, 'textFields' => $text_fields));
         // Assign template vars related to the category + execute hooks related to the category
         $this->assignCategory();
         // Assign template vars related to the price and tax
         $this->assignPriceAndTax();
         // Assign template vars related to the images
         $this->assignImages();
         $this->assign3dImages();
         // Assign attribute groups to the template
         $this->assignAttributesGroups();
         // Assign attributes combinations to the template
         $this->assignAttributesCombinations();
         // Pack management
         $pack_items = $this->product->cache_is_pack ? Pack::getItemTable($this->product->id, $this->context->language->id, true) : array();
         if (is_array($pack_items) && count($pack_items)) {
             foreach ($pack_items as &$pack_item) {
                 $pack_item['features'] = Product::getFrontFeaturesStatic($this->context->language->id, $pack_item['id_product']);
             }
         }
         $this->context->smarty->assign('packItems', $pack_items);
         $this->context->smarty->assign('packs', Pack::getPacksTable($this->product->id, $this->context->language->id, true, 1));
         if (isset($this->category->id) && $this->category->id) {
             $return_link = Tools::safeOutput($this->context->link->getCategoryLink($this->category));
         } else {
             $return_link = 'javascript: history.back();';
         }
         //reviews
         //                        $average = ProductComment::getAverageGrade((int)Tools::getValue('id_product'));
         $nbComments = (int) ProductComment::getCommentNumber((int) Tools::getValue('id_product'));
         $act_pack = 0;
         //паки
         if (!$flag_pack) {
             $sql = "SELECT DISTINCT(id_product_pack) FROM " . _DB_PREFIX_ . "pack WHERE id_product_item={$this->product->id}";
             $pack_products = array();
             $result_packs = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
             if (is_array($result_packs) && count($result_packs)) {
                 foreach ($result_packs as $k => $id_product_pack) {
                     $prod = new Product($id_product_pack['id_product_pack'], $this->context->language->id, true);
                     $cover = $prod->getCover((int) $prod->id);
                     if ($cover) {
                         $pack_products[$k]['id_image'] = $cover['id_image'];
                     } else {
                         $pack_products[$k]['id_image'] = null;
                     }
                     $price = $prod->getPrice(true, null, 2);
                     $price_old = $prod->getPriceWithoutReduct(false, null, 2);
                     if (isset($prod->specificPrice) && is_array($prod->specificPrice)) {
                         $pack_products[$k]['sale_percentage'] = $prod->specificPrice['reduction_type'] == 'percentage' ? $prod->specificPrice['reduction'] * 100 : $prod->specificPrice['reduction'] / $price_old * 100;
                     }
                     $pack_products[$k]['active'] = $prod->active;
                     if ($prod->active) {
                         $act_pack = 1;
                     }
                     $pack_products[$k]['count_reviews'] = (int) ProductComment::getCommentNumber((int) $prod->id);
                     $pack_products[$k]['star_reviews'] = ProductComment::getRatings((int) $prod->id);
                     $pack_products[$k]['price'] = $price;
                     $pack_products[$k]['price_old'] = $price_old;
                     $pack_products[$k]['on_sale'] = (bool) ($price != $price_old);
                     $pack_products[$k]['id_product_pack'] = $prod->id;
                     $pack_products[$k]['link'] = $this->context->link->getProductLink($prod);
                     $pack_products[$k]['name'] = $prod->name;
                     $pack_products[$k]['link_rewrite'] = $prod->link_rewrite;
                     $pack_products[$k]['items'] = Pack::getItemTable($prod->id, $this->context->language->id, true);
                     unset($prod);
                 }
             }
         } else {
             $pack_products = null;
         }
         //var_dump($pack_products);exit();
         //текстовой блок доставка
         $cms_block = '';
         $cms = new CMS($this->block_cms_id, $this->context->language->id);
         if (is_object($cms)) {
             $cms_block = $cms->content;
         }
         $sql = "SELECT id_category FROM ps_category_product WHERE id_product={$this->product->id}";
         $result_cats = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($sql);
         $params_image = null;
         foreach ($result_cats as $cat) {
             $params_image = file_exists(_PS_IMG_DIR_ . '/c_icon/' . $cat['id_category'] . '.png') ? '/img/c_icon/' . $cat['id_category'] . '.png' : null;
             if (!$params_image) {
                 $params_image = file_exists(_PS_IMG_DIR_ . '/c_icon/' . $cat['id_category'] . '.jpg') ? '/img/c_icon/' . $cat['id_category'] . '.jpg' : null;
             }
             if ($params_image) {
                 break;
             }
         }
         //{if $product->minimal_quantity > 1}{$product->minimal_quantity}{else}1{/if}
         $this->context->smarty->assign(array('is_bestsaler' => ProductSale::isBestsaler($this->product->id), 'og_type' => 'product', 'params_image' => $params_image, 'cms_block' => $cms_block, 'pack_products' => $pack_products, 'act_pack' => $act_pack, 'url' => $this->context->link->getProductLink($this->product), 'minimal_quantity' => $this->product->minimal_quantity > 1 ? $this->product->minimal_quantity : 1, 'nbComments' => $nbComments, 'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'), 'customizationFields' => $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->id) : false, 'accessories' => $this->product->getAccessories($this->context->language->id), 'return_link' => $return_link, 'product' => $this->product, 'product_manufacturer' => new Manufacturer((int) $this->product->id_manufacturer, $this->context->language->id), 'token' => Tools::getToken(false), 'features' => $this->product->getFrontFeatures($this->context->language->id), 'attachments' => $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->id) : array(), 'allow_oosp' => $this->product->isAvailableWhenOutOfStock((int) $this->product->out_of_stock), 'last_qties' => (int) Configuration::get('PS_LAST_QTIES'), 'HOOK_EXTRA_LEFT' => Hook::exec('displayLeftColumnProduct'), 'HOOK_EXTRA_RIGHT' => Hook::exec('displayRightColumnProduct'), 'HOOK_PRODUCT_OOS' => Hook::exec('actionProductOutOfStock', array('product' => $this->product)), 'HOOK_PRODUCT_ACTIONS' => Hook::exec('displayProductButtons', array('product' => $this->product)), 'HOOK_PRODUCT_TAB' => Hook::exec('displayProductTab', array('product' => $this->product)), 'HOOK_PRODUCT_TAB_CONTENT' => Hook::exec('displayProductTabContent', array('product' => $this->product)), 'HOOK_PRODUCT_CONTENT' => Hook::exec('displayProductContent', array('product' => $this->product)), 'display_qties' => (int) Configuration::get('PS_DISPLAY_QTIES'), 'display_ht' => !Tax::excludeTaxeOption(), 'currencySign' => $this->context->currency->sign, 'currencyRate' => $this->context->currency->conversion_rate, 'currencyFormat' => $this->context->currency->format, 'currencyBlank' => $this->context->currency->blank, 'jqZoomEnabled' => Configuration::get('PS_DISPLAY_JQZOOM'), 'ENT_NOQUOTES' => ENT_NOQUOTES, 'outOfStockAllowed' => (int) Configuration::get('PS_ORDER_OUT_OF_STOCK'), 'errors' => $this->errors, 'body_classes' => array($this->php_self . '-' . $this->product->id, $this->php_self . '-' . $this->product->link_rewrite, 'category-' . (isset($this->category) ? $this->category->id : ''), 'category-' . (isset($this->category) ? $this->category->getFieldByLang('link_rewrite') : '')), 'display_discount_price' => Configuration::get('PS_DISPLAY_DISCOUNT_PRICE')));
     }
     if (isset($_GET['quick_view'])) {
         $this->ajax = true;
         if ($flag_pack) {
             $this->setTemplate(_PS_THEME_DIR_ . 'preview_pack.tpl');
         } else {
             $this->setTemplate(_PS_THEME_DIR_ . 'preview.tpl');
         }
     } else {
         if ($flag_pack) {
             $this->setTemplate(_PS_THEME_DIR_ . 'product-pack.tpl');
         } else {
             $this->setTemplate(_PS_THEME_DIR_ . 'product.tpl');
         }
     }
 }