public function deleteVirtualProduct()
 {
     if (!($id_product_download = ProductDownload::getIdFromIdProduct(Tools::getValue('id_product')))) {
         return false;
     }
     $productDownload = new ProductDownload(intval($id_product_download));
     return $productDownload->deleteFile();
 }
Beispiel #2
0
 public function initProcess()
 {
     if (Tools::isSubmit('submitAddproductAndStay') || Tools::isSubmit('submitAddproduct')) {
         $this->id_object = (int) Tools::getValue('id_product');
         //echo 123; var_dump($this->id_object);
         $this->object = new Product($this->id_object);
         if ($this->object->is_virtual && (int) Tools::getValue('type_product') != 2) {
             if ($id_product_download = (int) ProductDownload::getIdFromIdProduct($this->id_object)) {
                 $product_download = new ProductDownload($id_product_download);
                 if (!$product_download->deleteFile($id_product_download)) {
                     $this->errors[] = Tools::displayError('Cannot delete file');
                 }
             }
         }
     }
     // Delete a product in the download folder
     if (Tools::getValue('deleteVirtualProduct')) {
         if ($this->tabAccess['delete'] === '1') {
             $this->action = 'deleteVirtualProduct';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('submitAddProductAndPreview')) {
         $this->display = 'edit';
         $this->action = 'save';
         if (Tools::getValue('id_product')) {
             $this->id_object = Tools::getValue('id_product');
             $this->object = new Product((int) Tools::getValue('id_product'));
         }
     } elseif (Tools::isSubmit('submitAttachments')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'attachments';
             $this->tab_display = 'attachments';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::getIsset('duplicate' . $this->table)) {
         if ($this->tabAccess['add'] === '1') {
             $this->action = 'duplicate';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to add this.');
         }
     } elseif (Tools::getValue('id_image') && Tools::getValue('ajax')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'image';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitProductAttribute')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'productAttribute';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitFeatures') || Tools::isSubmit('submitFeaturesAndStay')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'features';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitPricesModification')) {
         if ($this->tabAccess['add'] === '1') {
             $this->action = 'pricesModification';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to add this.');
         }
     } elseif (Tools::isSubmit('deleteSpecificPrice')) {
         if ($this->tabAccess['delete'] === '1') {
             $this->action = 'deleteSpecificPrice';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('submitSpecificPricePriorities')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'specificPricePriorities';
             $this->tab_display = 'prices';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitCustomizationConfiguration')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'customizationConfiguration';
             $this->tab_display = 'customization';
             $this->display = 'edit';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitProductCustomization')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'productCustomization';
             $this->tab_display = 'customization';
             $this->display = 'edit';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     }
     if (!$this->action) {
         parent::initProcess();
     } else {
         $this->id_object = (int) Tools::getValue($this->identifier);
     }
     if (isset($this->available_tabs[Tools::getValue('key_tab')])) {
         $this->tab_display = Tools::getValue('key_tab');
     }
     // Set tab to display if not decided already
     if (!$this->tab_display && $this->action) {
         if (in_array($this->action, array_keys($this->available_tabs))) {
             $this->tab_display = $this->action;
         }
     }
     // And if still not set, use default
     if (!$this->tab_display) {
         if (in_array($this->default_tab, $this->available_tabs)) {
             $this->tab_display = $this->default_tab;
         } else {
             $this->tab_display = key($this->available_tabs);
         }
     }
 }
 public function ajaxProcessDeleteVirtualProduct()
 {
     if (!($id_product_download = ProductDownload::getIdFromIdProduct((int) Tools::getValue('id_product')))) {
         $this->jsonError($this->l('Cannot retrieve file'));
     } else {
         $product_download = new ProductDownload((int) $id_product_download);
         if (!$product_download->deleteFile((int) $id_product_download)) {
             $this->jsonError($this->l('Cannot delete file'));
         } else {
             $this->jsonConfirmation($this->_conf[1]);
         }
     }
 }
 public function initProcess()
 {
     if (Tools::isSubmit('submitAddproductAndStay') || Tools::isSubmit('submitAddproduct')) {
         $this->id_object = (int) Tools::getValue('id_product');
         $this->object = new Product($this->id_object);
         if ($this->isTabSubmitted('Informations') && $this->object->is_virtual && (int) Tools::getValue('type_product') != 2) {
             if ($id_product_download = (int) ProductDownload::getIdFromIdProduct($this->id_object)) {
                 $product_download = new ProductDownload($id_product_download);
                 if (!$product_download->deleteFile($id_product_download)) {
                     $this->errors[] = Tools::displayError('Cannot delete file');
                 }
             }
         }
     }
     // Delete a product in the download folder
     if (Tools::getValue('deleteVirtualProduct')) {
         if ($this->tabAccess['delete'] === '1') {
             $this->action = 'deleteVirtualProduct';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('submitAddProductAndPreview')) {
         $this->display = 'edit';
         $this->action = 'save';
         if (Tools::getValue('id_product')) {
             $this->id_object = Tools::getValue('id_product');
             $this->object = new Product((int) Tools::getValue('id_product'));
         }
     } elseif (Tools::isSubmit('submitAttachments')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'attachments';
             $this->tab_display = 'attachments';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::getIsset('duplicate' . $this->table)) {
         if ($this->tabAccess['add'] === '1') {
             $this->action = 'duplicate';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to add this.');
         }
     } elseif (Tools::getValue('id_image') && Tools::getValue('ajax')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'image';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitProductAttribute')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'productAttribute';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitFeatures') || Tools::isSubmit('submitFeaturesAndStay')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'features';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitPricesModification')) {
         if ($this->tabAccess['add'] === '1') {
             $this->action = 'pricesModification';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to add this.');
         }
     } elseif (Tools::isSubmit('deleteSpecificPrice')) {
         if ($this->tabAccess['delete'] === '1') {
             $this->action = 'deleteSpecificPrice';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to delete this.');
         }
     } elseif (Tools::isSubmit('submitSpecificPricePriorities')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'specificPricePriorities';
             $this->tab_display = 'prices';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitCustomizationConfiguration')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'customizationConfiguration';
             $this->tab_display = 'customization';
             $this->display = 'edit';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('submitProductCustomization')) {
         if ($this->tabAccess['edit'] === '1') {
             $this->action = 'productCustomization';
             $this->tab_display = 'customization';
             $this->display = 'edit';
         } else {
             $this->errors[] = Tools::displayError('You do not have permission to edit this.');
         }
     } elseif (Tools::isSubmit('id_product')) {
         $post_max_size = Tools::getMaxUploadSize(Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE') * 1024 * 1024);
         if ($post_max_size && isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH'] && $_SERVER['CONTENT_LENGTH'] > $post_max_size) {
             $this->errors[] = sprintf(Tools::displayError('The uploaded file exceeds the "Maximum size for a downloadable product" set in preferences (%1$dMB) or the post_max_size/ directive in php.ini (%2$dMB).'), number_format(Configuration::get('PS_LIMIT_UPLOAD_FILE_VALUE')), $post_max_size / 1024 / 1024);
         }
     }
     if (!$this->action) {
         parent::initProcess();
     } else {
         $this->id_object = (int) Tools::getValue($this->identifier);
     }
     if (isset($this->available_tabs[Tools::getValue('key_tab')])) {
         $this->tab_display = Tools::getValue('key_tab');
     }
     // Set tab to display if not decided already
     if (!$this->tab_display && $this->action) {
         if (in_array($this->action, array_keys($this->available_tabs))) {
             $this->tab_display = $this->action;
         }
     }
     // And if still not set, use default
     if (!$this->tab_display) {
         if (in_array($this->default_tab, $this->available_tabs)) {
             $this->tab_display = $this->default_tab;
         } else {
             $this->tab_display = key($this->available_tabs);
         }
     }
 }
 public function processDeleteVirtualProduct()
 {
     if (!($id_product_download = ProductDownload::getIdFromIdProduct((int) Tools::getValue('id_product')))) {
         $this->errors[] = Tools::displayError('Cannot retrieve file');
     } else {
         $product_download = new ProductDownload((int) $id_product_download);
         if (!$product_download->deleteFile((int) $id_product_download)) {
             $this->errors[] = Tools::displayError('Cannot delete file');
         } else {
             $this->redirect_after = self::$currentIndex . '&id_product=' . (int) Tools::getValue('id_product') . '&updateproduct&key_tab=VirtualProduct&conf=1&token=' . $this->token;
         }
     }
     $this->display = 'edit';
     $this->tab_display = 'VirtualProduct';
 }
Beispiel #6
0
 public function deleteVirtualProduct()
 {
     if (!($id_product_download = ProductDownload::getIdFromIdProduct((int) Tools::getValue('id_product'))) && !Tools::getValue('file')) {
         return false;
     }
     $file = Tools::getValue('file');
     $productDownload = new ProductDownload((int) $id_product_download);
     $return = $productDownload->deleteFile();
     if (!$return && file_exists(_PS_DOWNLOAD_DIR_ . $file)) {
         $return = unlink(_PS_DOWNLOAD_DIR_ . $file);
     }
     return $return;
 }