Example #1
0
 public function display($tpl = null)
 {
     if (!isset($this->context) || $this->context == null) {
         $this->context = JeproshopContext::getContext();
     }
     if (!$this->context->controller->isInitialized()) {
         $this->context->controller->initialize();
     }
     $app = JFactory::getApplication();
     $useSSL = isset($this->context->controller->ssl_enabled) && $this->context->conteoller->ssl_enabled && $app->input->get('enable_ssl') || JeproshopTools::usingSecureMode() ? true : false;
     $protocol_content = $useSSL ? 'https://' : 'http://';
     /*$contextParams = $this->context->controller->getContextParams();
       foreach ($contextParams as $assign_key => $assign_value){
           if (!is_array($assign_value) && mb_substr($assign_value, 0, 1, 'utf-8') == '/' || $protocol_content == 'https://'){
               $this->assignRef($assign_key, $protocol_content.JeproshopTools::getMediaServer($assign_value).$assign_value);
           }else{
               $this->assignRef($assign_key, $assign_value);
           }
       }*/
     if (!isset(self::$cache_products)) {
         $category = new JeproshopCategoryModelCategory(JeproshopContext::getContext()->shop->getCategoryId(), (int) JeproshopContext::getContext()->language->lang_id);
         $nb = (int) JeproshopSettingModelSetting::getValue('number_of_products_on_page');
         self::$cache_products = JeproshopDefaultModelDefault::getProducts((int) JeproshopContext::getContext()->language->lang_id, 0, $nb ? $nb : 8, 'position');
     }
     if (self::$cache_products === false || empty(self::$cache_products)) {
         self::$cache_products = false;
     }
     $this->assignRef('products', self::$cache_products);
     $display_add_product = JeproshopSettingModelSetting::getValue('display_category_attribute');
     $this->assignRef('display_add_product', $display_add_product);
     $homeSize = JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('home'));
     $this->assignRef('homeSize', $homeSize);
     $this->assignRef('pagination', JeproshopDefaultModelDefault::$_pagination);
     parent::display($tpl);
 }
Example #2
0
 /**
  * Assign scenes template vars
  */
 protected function assignScenes()
 {
     // Scenes (could be externalised to another controller if you need them)
     $scenes = JeproshopSceneModelScene::getScenes($this->category->category_id, $this->context->language->lang_id, true, false);
     $this->assignRef('scenes', $scenes);
     // Scenes images formats
     if ($scenes && ($sceneImageTypes = JeproshopImageTypeModelImageType::getImagesTypes('scenes'))) {
         foreach ($sceneImageTypes as $sceneImageType) {
             if ($sceneImageType->name == JeproshopImageTypeModelImageType::getFormatedName('m_scene')) {
                 $thumbSceneImageType = $sceneImageType;
             } elseif ($sceneImageType->name == JeproshopImageTypeModelImageType::getFormatedName('scene')) {
                 $largeSceneImageType = $sceneImageType;
             }
         }
         $this->assignRef('thumbSceneImageType', isset($thumbSceneImageType) ? $thumbSceneImageType : null);
         $this->assignRef('largeSceneImageType', isset($largeSceneImageType) ? $largeSceneImageType : null);
     }
 }
Example #3
0
 public function assignSummaryInformations()
 {
     $context = JeproshopContext::getContext();
     $summary = $context->cart->getSummaryDetails();
     $customizedDatas = JeproshopProductModelProduct::getAllCustomizedDatas($context->cart->cart_id);
     // override customization tax rate with real tax (tax rules)
     if ($customizedDatas) {
         foreach ($summary['products'] as &$productUpdate) {
             $productId = (int) (isset($productUpdate->product_id) ? $productUpdate->product_id : $productUpdate->product_id);
             $productAttributeId = (int) (isset($productUpdate->product_attribute_id) ? $productUpdate->product_attribute_id : $productUpdate->product_attribute_id);
             if (isset($customizedDatas[$productId][$productAttributeId])) {
                 $productUpdate->tax_rate = JeproshopTaxModelTax::getProductTaxRate($productId, $context->cart->{JeproshopSettingModelSetting::getValue('tax_address_type')});
             }
         }
         JeproshopProductModelProduct::addCustomizationPrice($summary->products, $customizedDatas);
     }
     $cart_product_context = JeproshopContext::getContext()->cloneContext();
     foreach ($summary['products'] as $key => $product) {
         $product->quantity = $product->cart_quantity;
         // for compatibility with 1.2 themes
         if ($cart_product_context->shop->shop_id != $product->shop_id) {
             $cart_product_context->shop = new JeproshopModelShop((int) $product->shop_id);
         }
         $null = null;
         $product->price_without_specific_price = JeproshopProductModelProduct::getStaticPrice($product->product_id, !JeproshopProductModelProduct::getTaxCalculationMethod(), $product->product_attribute_id, 2, null, false, false, 1, false, null, null, null, $null, true, true, $cart_product_context);
         if (JeproshopProductModelProduct::getTaxCalculationMethod()) {
             $product->is_discounted = $product->price_without_specific_price != $product->price;
         } else {
             $product->is_discounted = $product->price_without_specific_price != $product->price_wt;
         }
     }
     // Get available cart rules and unset the cart rules already in the cart
     $available_cart_rules = JeproshopCartRuleModelCartRule::getCustomerCartRules($this->context->language->lang_id, isset($this->context->customer->customer_id) ? $this->context->customer->customer_id : 0, true, true, true, $this->context->cart);
     $cart_cart_rules = $context->cart->getCartRules();
     foreach ($available_cart_rules as $key => $available_cart_rule) {
         if (!$available_cart_rule->high_light || strpos($available_cart_rule->code, 'BO_ORDER_') === 0) {
             unset($available_cart_rules[$key]);
             continue;
         }
         foreach ($cart_cart_rules as $cart_cart_rule) {
             if ($available_cart_rule->cart_rule_id == $cart_cart_rule->cart_rule_id) {
                 unset($available_cart_rules[$key]);
                 continue 2;
             }
         }
     }
     $show_option_allow_separate_package = !$this->context->cart->isAllProductsInStock(true) && JeproshopSettingModelSetting::getValue('ship_when_available');
     $this->assign($summary);
     //$this->assign('token_cart', Tools::getToken(false));
     $this->assign('is_logged', $this->context->controller->isLogged);
     $this->assign('is_virtual_cart', $this->context->cart->isVirtualCart());
     $this->assign('product_number', $this->context->cart->numberOfProducts());
     $this->assign('voucher_allowed', JeproshopCartRuleModelCartRule::isFeaturePublished());
     $this->assign('shipping_cost', $this->context->cart->getOrderTotal(true, JeproshopCartModelCart::ONLY_SHIPPING));
     $this->assign('shipping_cost_tax_excluded', $this->context->cart->getOrderTotal(false, JeproshopCartModelCart::ONLY_SHIPPING));
     $this->assign('customizedDatas', $customizedDatas);
     $this->assign('CUSTOMIZE_FILE', JeproshopProductModelProduct::CUSTOMIZE_FILE);
     $this->assign('CUSTOMIZE_TEXT_FIELD', JeproshopProductModelProduct::CUSTOMIZE_TEXT_FIELD);
     $this->assign('last_product_added', $this->context->cart->getLastProduct());
     $this->assign('display_vouchers', $available_cart_rules);
     $this->assign('currency_sign', $this->context->currency->sign);
     $this->assign('currency_rate', $this->context->currency->conversion_rate);
     $this->assign('currency_format', $this->context->currency->format);
     $this->assign('currency_blank', $this->context->currency->blank);
     $this->assign('show_option_allow_separate_package', $show_option_allow_separate_package);
     $this->assign('small_size', JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('small')));
     /*
             $this->context->smarty->assign(array(
                 'HOOK_SHOPPING_CART' => Hook::exec('displayShoppingCartFooter', $summary),
                 'HOOK_SHOPPING_CART_EXTRA' => Hook::exec('displayShoppingCart', $summary)
             ));*/
 }
Example #4
0
 /**
  * Delete the product image from disk and remove the containing folder if empty
  * Handles both legacy and new image filesystems
  * @param bool $force_delete
  * @return bool
  */
 public function deleteImage($force_delete = false)
 {
     if (!$this->image_id) {
         return false;
     }
     // Delete base image
     if (file_exists($this->image_dir . $this->getExistingImagePath() . '.' . $this->image_format)) {
         unlink($this->image_dir . $this->getExistingImagePath() . '.' . $this->image_format);
     } else {
         return false;
     }
     $files_to_delete = array();
     // Delete auto-generated images
     $image_types = JeproshopImageTypeModelImageType::getImagesTypes();
     foreach ($image_types as $image_type) {
         $files_to_delete[] = $this->image_dir . $this->getExistingImagePath() . '-' . $image_type->name . '.' . $this->image_format;
     }
     // Delete watermark image
     $files_to_delete[] = $this->image_dir . $this->getExistingImagePath() . '_watermark.' . $this->image_format;
     // delete index.php
     $files_to_delete[] = $this->image_dir . $this->getImageFolder() . 'index.php';
     // Delete tmp images
     $files_to_delete[] = COM_JEPROSHOP_TEMP_IMAGE_DIR . 'product_' . $this->product_id . '.' . $this->image_format;
     $files_to_delete[] = COM_JEPROSHOP_TEMP_IMAGE_DIR . 'product_mini_' . $this->product_id . '.' . $this->image_format;
     foreach ($files_to_delete as $file) {
         if (file_exists($file) && !@unlink($file)) {
             return false;
         }
     }
     // Can we delete the image folder?
     if (is_dir($this->image_dir . $this->getImageFolder())) {
         $delete_folder = true;
         foreach (scandir($this->image_dir . $this->getImageFolder()) as $file) {
             if ($file != '.' && $file != '..') {
                 $delete_folder = false;
                 break;
             }
         }
     }
     if (isset($delete_folder) && $delete_folder) {
         @rmdir($this->image_dir . $this->getImageFolder());
     }
     return true;
 }
Example #5
0
 /**
  * Assign template vars related to images
  */
 protected function assignImages()
 {
     $app = JFactory::getApplication();
     $images = $this->product->getImages((int) $this->context->cookie->lang_id);
     $product_images = array();
     if (isset($images[0])) {
         $this->assignRef('mainImage', $images[0]);
     }
     foreach ($images as $image) {
         if ($image->cover) {
             $this->assignRef('mainImage', $image);
             $cover = $image;
             $cover->image_id = JeproshopSettingModelSetting::getValue('legacy_images') ? $this->product->product_id . '_' . $image->image_id : $image->image_id;
             $cover->only_image_id = (int) $image->image_id;
         }
         $product_images[(int) $image->image_id] = $image;
     }
     if (!isset($cover)) {
         if (isset($images[0])) {
             $cover = $images[0];
             $cover->image_id = JeproshopSettingModelSetting::getValue('legacy_images') ? $this->product->product_id . '-' . $images[0]->image_id : $images[0]->image_id;
             $cover->only_image_id = (int) $images[0]->image_id;
         } else {
             $cover = new JObject();
             $cover->image_id = $this->context->language->iso_code . '_default';
             $cover->legend = JText::_('COM_JEPROSHOP_NO_PICTURE_LABEL');
             $cover->title = JText::_('COM_JEPROSHOP_NO_PICTURE_LABEL');
         }
     }
     $size = JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('large'));
     $has_image = isset($cover->image_id) && (int) $cover->image_id ? array((int) $cover->image_id) : JeproshopProductModelProduct::getCover((int) $app->input->get('product_id'));
     $this->assignRef('has_image', $has_image);
     $this->assignRef('cover', $cover);
     $width = (int) $size->width;
     $this->assignRef('image_width', $width);
     $medium_size = JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('medium'));
     $this->assignRef('medium_size', $medium_size);
     $large_size = JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('large'));
     $this->assignRef('large_size', $large_size);
     $home_size = JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('home'));
     $this->assignRef('home_size', $home_size);
     $cart_size = JeproshopImageModelImage::getSize(JeproshopImageTypeModelImageType::getFormatName('cart'));
     $this->assignRef('cart_size', $cart_size);
     //$this->assignRef('col_img_dir', _PS_COL_IMG_DIR_));
     if (count($product_images)) {
         $this->assignRef('images', $product_images);
     }
 }
Example #6
0
 private function initImagesForm()
 {
     if ((bool) $this->product->product_id) {
         if ($this->product_exists_in_shop) {
             $shops = false;
             if (JeproshopShopModelShop::isFeaturePublished()) {
                 $shops = JeproshopShopModelShop::getShops();
             }
             if ($shops) {
                 foreach ($shops as $key => $shop) {
                     if (!$this->product->isAssociatedToShop($shop->shop_id)) {
                         unset($shops[$key]);
                     }
                 }
             }
             $this->assignRef('shops', $shops);
             $db = JFactory::getDBO();
             $app = JFactory::getApplication();
             $query = "SELECT COUNT(product_id) FROM " . $db->quoteName('#__jeproshop_image');
             $query .= " WHERE product_id = " . (int) $this->product->product_id;
             $db->setQuery($query);
             $count_images = $db->loadResult();
             $images = JeproshopImageModelImage::getImages($this->context->language->lang_id, $this->product->product_id);
             foreach ($images as $k => $image) {
                 $images[$k] = new JeproshopImageModelImage($image->image_id);
             }
             if ($this->context->shop->getShopContext() == JeproshopShopModelShop::CONTEXT_SHOP) {
                 $current_shop_id = (int) $this->context->shop->shop_id;
             } else {
                 $current_shop_id = 0;
             }
             $languages = JeproshopLanguageModelLanguage::getLanguages(true);
             $image_uploader = new JeproshopImageUploader('file');
             $image_link = JRoute::_('index.php?option=com_jeproshop&view=product&ajax=1&product_id=' . (int) $this->product->product_id . '&task=add_product_image');
             $image_uploader->setMultiple(!(JeproshopTools::getUserBrowser() == 'Apple Safari' && JeproshopTools::getUserPlatform() == 'Windows'))->setUseAjax(true)->setUrl($image_link);
             $this->assignRef('countImages', $count_images);
             /*$this->assignRef(
               'id_product' => (int)Tools::getValue('id_product'),
               'id_category_default' => (int)$this->_category->id, */
             $this->assignRef('images', $images);
             /*'iso_lang' => $languages[0]['iso_code'],
               'token' =>  $this->token,
               'table' => $this->table,*/
             $image_size = (int) JeproshopSettingModelSetting::getValue('product_picture_max_size') / 1024 / 1024;
             $this->assignRef('max_image_size', $image_size);
             $virtualProductFilenameAttribute = (string) $app->input->get('virtual_product_filename_attribute');
             $this->assignRef('up_filename', $virtualProductFilenameAttribute);
             //'currency' => $this->context->currency,
             $this->assignRef('current_shop_id', $current_shop_id);
             //		'languages' => $this->_languages,
             //		'default_language' => (int)Configuration::get('PS_LANG_DEFAULT'),
             $imageUploader = $image_uploader->render();
             $this->assignRef('image_uploader', $imageUploader);
             //));
             $type = JeproshopImageTypeModelImageType::getByNameNType('%', 'products', 'height');
             if (isset($type->name)) {
                 $imageType = $type->name;
             } else {
                 $imageType = 'small_default';
             }
             $this->assignRef('image_type', $imageType);
         } else {
             $this->displayWarning($this->l('You must save the product in this shop before adding images.'));
         }
     }
 }