示例#1
0
 /**
  * Check if order contains (only) virtual products
  *
  * @param boolean $strict If false return true if there are at least one product virtual
  * @return boolean true if is a virtual order or false
  *
  */
 public function isVirtual($strict = true)
 {
     $products = $this->getProducts();
     if (count($products) < 1) {
         return false;
     }
     $virtual = true;
     foreach ($products as $product) {
         $pd = JeproshopProductDownloadModelProductDownload::getIdFromProductId((int) $product->product_id);
         if ($pd && JeproshopTools::isUnsignedInt($pd) && $product->download_hash && $product->display_filename != '') {
             if ($strict === false) {
                 return true;
             }
         } else {
             $virtual &= false;
         }
     }
     return $virtual;
 }
示例#2
0
 /**
  * Check if cart contains only virtual products
  * @return bool true if is a virtual cart or false
  */
 public function isVirtualCart()
 {
     if (!JeproshopProductDownloadModelProductDownload::isFeaturePublished()) {
         return false;
     }
     if (!isset(self::$_isVirtualCart[$this->cart_id])) {
         $products = $this->getProducts();
         if (!count($products)) {
             return false;
         }
         $is_virtual = 1;
         foreach ($products as $product) {
             if (empty($product->is_virtual)) {
                 $is_virtual = 0;
             }
         }
         self::$_isVirtualCart[$this->cart_id] = (int) $is_virtual;
     }
     return self::$_isVirtualCart[$this->cart_id];
 }
示例#3
0
 /**
  * Get order products
  *
  * @param bool $products
  * @param bool $selectedProducts
  * @param bool $selectedQty
  * @return array Products with price, quantity (with tax and without)
  */
 public function getProducts($products = false, $selectedProducts = false, $selectedQty = false)
 {
     if (!$products) {
         $products = $this->getProductsDetail();
     }
     $customized_datas = JeproshopProductModelProduct::getAllCustomizedDatas($this->cart_id);
     $resultArray = array();
     foreach ($products as $row) {
         // Change qty if selected
         if ($selectedQty) {
             $row->product_quantity = 0;
             foreach ($selectedProducts as $key => $product_id) {
                 if ($row->order_detail_id == $product_id) {
                     $row->product_quantity = (int) $selectedQty[$key];
                 }
             }
             if (!$row->product_quantity) {
                 continue;
             }
         }
         $this->setProductImageInformations($row);
         $this->setProductCurrentStock($row);
         // Backward compatibility 1.4 -> 1.5
         $this->setProductPrices($row);
         $this->setProductCustomizedDatas($row, $customized_datas);
         // Add information for virtual product
         if ($row->download_hash && !empty($row->download_hash)) {
             $row->filename = JeproshopProductDownloadModelProductDownload::getFilenameFromProductIdId((int) $row->product_id);
             // Get the display filename
             $row->display_filename = JeproshopProductDownloadModelProductDownload::getFilenameFromFilename($row->filename);
         }
         $row->address_delivery_id = $this->address_delivery_id;
         /* Stock product */
         $resultArray[(int) $row->order_detail_id] = $row;
     }
     if ($customized_datas) {
         JeproshopProductModelProduct::addCustomizationPrice($resultArray, $customized_datas);
     }
     return $resultArray;
 }
示例#4
0
 /**
  * Return the id_product_download from an id_product
  *
  * @param int $product_id Product the id
  * @return integer Product the id for this virtual product
  */
 public static function getIdFromProductId($product_id)
 {
     if (!JeproshopProductDownloadModelProductDownload::isFeaturePublished()) {
         return false;
     }
     if (array_key_exists((int) $product_id, self::$_productIds)) {
         return self::$_productIds[$product_id];
     }
     $db = JFactory::getDBO();
     $query = "SELECT " . $db->quoteName('product_download_id') . " FROM " . $db->quoteName('#__jeproshop_product_download');
     $query .= " WHERE " . $db->quoteName('product_id') . " = " . (int) $product_id . " AND " . $db->quoteName('published') . " = 1 ";
     $query .= "\tORDER BY " . $db->quoteName('product_download_id') . " DESC";
     $db->setQuery($query);
     self::$_productIds[$product_id] = (int) $db->loadResult();
     return self::$_productIds[$product_id];
 }
示例#5
0
 public function renderView($tpl = null)
 {
     $app = JFactory::getApplication();
     if (!isset($this->context) && null == $this->context) {
         $this->context = JeproshopContext::getContext();
     }
     if (!isset($this->context->cart)) {
         $this->context->cart = new JeproshopCartModelCart();
     }
     if (!$this->context->controller->isInitialized()) {
         $this->initialize();
     }
     $useSSL = isset($this->context->controller->ssl_enabled) && $this->context->controller->ssl_enabled && $app->input->get('enable_ssl') || JeproshopTools::usingSecureMode() ? true : false;
     $protocol_content = $useSSL ? 'https://' : 'http://';
     $this->loadObject();
     if (JeproshopProductPack::isPack((int) $this->product->product_id) && !JeproshopProductPack::isInStock((int) $this->product->product_id)) {
         $this->product->quantity = 0;
     }
     $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.
     $virtual = JeproshopProductDownloadModelProductDownload::getIdFromProductId((int) $this->product->product_id);
     $this->assignRef('virtual', $virtual);
     $customization_form_target = JeproshopTools::safeOutput(urldecode($_SERVER['REQUEST_URI']));
     $this->assignRef('customization_form_target', $customization_form_target);
     $delete_picture = $app->input->get('delete_picture');
     if ($app->input->get('submit_customized_datas')) {
         // 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->cart_id && isset($_COOKIE[$this->context->cookie->getName()])) {
             $this->context->cart->add();
             $this->context->cookie->cart_id = (int) $this->context->cart->cart_id;
         }
         $this->pictureUpload();
         $this->textRecord();
         $this->formTargetFormat();
     } else {
         if (isset($delete_picture) && !$this->context->cart->deleteCustomizationToProduct($this->product->product_id, $app->input->get('delete_picture'))) {
             $this->errors[] = JText::_('An error occurred while deleting the selected picture.');
         }
     }
     $pictures = array();
     $text_fields = array();
     if ($this->product->customizable) {
         $files = $this->context->cart->getProductCustomization($this->product->product_id, JeproshopProductModelProduct::CUSTOMIZE_FILE, true);
         foreach ($files as $file) {
             $pictures['pictures_' . $this->product->product_id . '_' . $file['index']] = $file['value'];
         }
         $texts = $this->context->cart->getProductCustomization($this->product->product_id, JeproshopProductModelProduct::CUSTOMIZE_TEXT_FIELD, true);
         foreach ($texts as $text_field) {
             $text_fields['textFields_' . $this->product->product_id . '_' . $text_field['index']] = str_replace('<br />', "\n", $text_field['value']);
         }
     }
     $this->assignRef('pictures', $pictures);
     $this->assignRef('textFields', $text_fields);
     $this->product->customization_required = false;
     $customizationFields = $this->product->customizable ? $this->product->getCustomizationFields($this->context->language->lang_id) : false;
     if (is_array($customizationFields)) {
         foreach ($customizationFields as $customizationField) {
             if ($this->product->customization_required = $customizationField['required']) {
                 break;
             }
         }
     }
     // 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();
     // 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 ? JeproshopProductPack::getItemTable($this->product->product_id, $this->context->language->lang_id, true) : array();
     $this->assignRef('packItems', $pack_items);
     $packs = JeproshopProductPack::getPacksTable($this->product->product_id, $this->context->language->lang_id, true, 1);
     $this->assignRef('packs', $packs);
     if (isset($this->category->category_id) && $this->category->category_id) {
         $return_link = JeproshopTools::safeOutput($this->context->controller->getCategoryLink($this->category));
     } else {
         $return_link = 'javascript: history.back();';
     }
     if (!$this->context->controller->useMobileTheme()) {
     }
     //'stock_management' => Configuration::get('PS_STOCK_MANAGEMENT'),
     //		'customizationFields' => $customizationFields,
     $accessories = $this->product->getAccessories($this->context->language->lang_id);
     $this->assignRef('accessories', $accessories);
     $enable_jqzoom = JeproshopSettingModelSetting::getValue('enable_jqzoom');
     $this->assignRef('jqZoomEnabled', $enable_jqzoom);
     $manufacturer = new JeproshopManufacturerModelManufacturer((int) $this->product->manufacturer_id, $this->context->language->lang_id);
     $this->assignRef('product_manufacturer', $manufacturer);
     $features = $this->product->getFrontFeatures($this->context->language->lang_id);
     $this->assignRef('features', $features);
     $attachments = $this->product->cache_has_attachments ? $this->product->getAttachments($this->context->language->lang_id) : array();
     $this->assignRef('attachments', $attachments);
     $display_discount_price = JeproshopSettingModelSetting::getValue('display_discount_price');
     $this->assignRef('display_discount_price', $display_discount_price);
     $this->assignRef('return_link', $return_link);
     $content_only = $app->input->get('content_only');
     $this->assignRef('content_only', $content_only);
     $last_quantities = JeproshopSettingModelSetting::getValue('last_quantities');
     $this->assignRef('last_quantities', $last_quantities);
     $display_quantities = JeproshopSettingModelSetting::getValue('display_quantities');
     $this->assignRef('display_quantities', $display_quantities);
     $allow_out_of_stock_ordering = JeproshopSettingModelSetting::getValue('allow_out_of_stock_ordering');
     $this->assignRef('allow_out_of_stock_ordering', $allow_out_of_stock_ordering);
     $catalog_mode = (bool) (JeproshopSettingModelSetting::getValue('catalog_mode') || !JeproshopGroupModelGroup::getCurrent()->show_prices);
     $this->assignRef('catalog_mode', $catalog_mode);
     $extra_left = null;
     $this->assignRef('extra_left', $extra_left);
     $extra_right = null;
     $this->assignRef('extra_right', $extra_right);
     parent::display($tpl);
 }
示例#6
0
 private function initInformationsForm()
 {
     if (!$this->context->controller->default_form_language) {
         $this->languages = $this->context->controller->getLanguages();
     }
     $app = JFactory::getApplication();
     $product_name_redirected = JeproshopProductModelProduct::getProductName((int) $this->product->product_redirected_id, null, (int) $this->context->language->lang_id);
     $this->assignRef('product_name_redirected', $product_name_redirected);
     /*
      * Form for adding a virtual product like software, mp3, etc...
      */
     $product_download = new JeproshopProductDownloadModelProductDownload();
     $product_download_id = $product_download->getIdFromProductId($this->product->product_id);
     if ($product_download_id) {
         $product_download = new JeproshopProductDownloadModelProductDownload($product_download_id);
     }
     $this->product->productDownload = $product_download;
     $cache_default_attribute = (int) $this->product->cache_default_attribute;
     $product_props = array();
     // global informations
     array_push($product_props, 'reference', 'ean13', 'upc', 'available_for_order', 'show_price', 'online_only', 'manufacturer_id');
     // specific / detailed information
     array_push($product_props, 'width', 'height', 'weight', 'published', 'is_virtual', 'cache_default_attribute', 'uploadable_files', 'text_fields');
     // prices
     array_push($product_props, 'price', 'wholesale_price', 'tax_rules_group_id', 'unit_price_ratio', 'on_sale', 'unity', 'minimal_quantity', 'additional_shipping_cost', 'available_now', 'available_later', 'available_date');
     if (JeproshopSettingModelSetting::getValue('use_eco_tax')) {
         array_push($product_props, 'ecotax');
     }
     $this->product->name['class'] = 'updateCurrentText';
     if (!$this->product->product_id || JeproshopSettingModelSetting::getValue('force_friendly_product')) {
         $this->product->name['class'] .= ' copy2friendlyUrl';
     }
     $images = JeproshopImageModelImage::getImages($this->context->language->lang_id, $this->product->product_id);
     if (is_array($images)) {
         foreach ($images as $k => $image) {
             //$images[$k]->src = $this->context->controller->getImageLink($this->product->link_rewrite[$this->context->language->lang_id], $this->product->product_id.'-'.$image->image_id, 'small_default'); echo $images[$k]->src;
         }
         $this->assignRef('product_images', $images);
     }
     $imagesTypes = JeproshopImageTypeModelImageType::getImagesTypes('products');
     $this->assignRef('imagesTypes', $imagesTypes);
     $this->product->tags = JeproshopTagModelTag::getProductTags($this->product->product_id);
     $product_type = (int) $app->input->get('product_type', $this->product->getType());
     $this->assignRef('product_type', $product_type);
     $is_in_pack = (int) JeproshopProductPack::isPacked($this->product->product_id);
     $this->assignRef('is_in_pack', $is_in_pack);
     $check_product_association_ajax = false;
     if (JeproshopShopModelShop::isFeaturePublished() && JeproshopShopModelShop::getShopContext() != JeproshopShopModelShop::CONTEXT_ALL) {
         $check_product_association_ajax = true;
     }
     $iso_tiny_mce = $this->context->language->iso_code;
     $iso_tiny_mce = file_exists(JURI::base() . '/components/com_jeproshop/assets/javascript/tiny_mce/langs/' . $iso_tiny_mce . '.js') ? $iso_tiny_mce : 'en';
     $this->assignRef('iso_tiny_mce', $iso_tiny_mce);
     $this->assignRef('check_product_association_ajax', $check_product_association_ajax);
     $combinationImageJs = $this->getCombinationImagesJs();
     $this->assignRef('combinationImagesJs', $combinationImageJs);
 }