Ejemplo n.º 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;
 }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
 /**
  * Update product download
  *
  * @param int $edit
  * @return bool
  */
 public function updateDownloadProduct($edit = 0)
 {
     $app = JFactory::getApplication();
     if ((int) $app->input->get('is_virtual_file') == 1) {
         if (isset($_FILES['virtual_product_file_uploader']) && $_FILES['virtual_product_file_uploader']['size'] > 0) {
             $virtual_product_filename = JeproshopProductDownloadModelProductDownload::getNewFilename();
             $helper = new HelperUploader('virtual_product_file_uploader');
             $files = $helper->setPostMaxSize(Tools::getOctets(ini_get('upload_max_filesize')))->setSavePath(_PS_DOWNLOAD_DIR_)->upload($_FILES['virtual_product_file_uploader'], $virtual_product_filename);
         } else {
             $virtual_product_filename = $app->input->get('virtual_product_filename', JeproshopProductDownloadModelProductDownload::getNewFilename());
         }
         $this->setDefaultAttribute(0);
         //reset cache_default_attribute
         if ($app->input->get('virtual_product_expiration_date') && !JeproshopTools::isDate($app->input->get('virtual_product_expiration_date'))) {
             if (!$app->input->get('virtual_product_expiration_date')) {
                 JText::_('The expiration-date attribute is required.');
                 $this->context->controller->has_errors = true;
                 return false;
             }
         }
         // Trick's
         if ($edit == 1) {
             $product_download_id = (int) JeproshopProductDownloadModelProductDownload::getIdFromProductId((int) $this->product_id);
             if (!$product_download_id) {
                 $product_download_id = (int) $app->input->get('virtual_product_id');
             }
         } else {
             $product_download_id = $app->input->get('virtual_product_id');
         }
         $is_sharable = $app->input->get('virtual_product_is_sharable');
         $virtual_product_name = $app->input->get('virtual_product_name');
         $virtual_product_nb_days = $app->input->get('virtual_product_nb_days');
         $virtual_product_nb_downloadable = $app->input->get('virtual_product_nb_downloadable');
         $virtual_product_expiration_date = $app->input->get('virtual_product_expiration_date');
         $download = new JeproshopProductDownloadModelProductDownload((int) $product_download_id);
         $download->product_id = (int) $this->product_id;
         $download->display_filename = $virtual_product_name;
         $download->filename = $virtual_product_filename;
         $download->date_add = date('Y-m-d H:i:s');
         $download->date_expiration = $virtual_product_expiration_date ? $virtual_product_expiration_date . ' 23:59:59' : '';
         $download->nb_days_accessible = (int) $virtual_product_nb_days;
         $download->nb_downloadable = (int) $virtual_product_nb_downloadable;
         $download->published = 1;
         $download->is_sharable = (int) $is_sharable;
         if ($download->save()) {
             return true;
         }
     } else {
         /* un-active download product if checkbox not checked */
         if ($edit == 1) {
             $product_download_id = (int) JeproshopProductDownloadModelProductDownload::getIdFromProductId((int) $this->product_id);
             if (!$product_download_id) {
                 $product_download_id = (int) $app->input->get('virtual_product_id');
             }
         } else {
             $product_download_id = JeproshopProductDownloadModelProductDownload::getIdFromProductId($this->product_id);
         }
         if (!empty($product_download_id)) {
             $product_download = new JeproshopProductDownloadModelProductDownload((int) $product_download_id);
             $product_download->date_expiration = date('Y-m-d H:i:s', time() - 1);
             $product_download->published = 0;
             return $product_download->save();
         }
     }
     return false;
 }