public function deleteProduct($products_id, $categories_id = '', $use_page_uid = false)
 {
     if (!is_numeric($products_id)) {
         return false;
     }
     if (is_numeric($products_id)) {
         $productRow = mslib_fe::getProduct($products_id, '', '', 1, 1);
         if (is_numeric($products_id)) {
             if (is_numeric($categories_id)) {
                 //hook to let other plugins further manipulate the create table query
                 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_befe.php']['deleteProductPreHook'])) {
                     $params = array('products_id' => &$products_id, 'categories_id' => &$categories_id);
                     foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_befe.php']['deleteProductPreHook'] as $funcRef) {
                         \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
                     }
                 }
                 // just delete the relation to the category
                 $qry = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_multishop_products_to_categories', 'products_id=' . $products_id . ' and categories_id=' . $categories_id);
                 // count if there are relations left
                 $str = $GLOBALS['TYPO3_DB']->SELECTquery('count(1) as total', 'tx_multishop_products_to_categories', "products_id='" . $products_id . "' and is_deepest=1", '', '', '');
                 //var_dump($str);
                 //die();
                 //
                 $qry = $GLOBALS['TYPO3_DB']->sql_query($str);
                 $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry);
                 if ($row['total']) {
                     // dont delete the product, cause there is another category that has relation
                     return true;
                 } else {
                     $definitive_delete = 1;
                 }
             } else {
                 $definitive_delete = 1;
             }
             if ($definitive_delete) {
                 //hook to let other plugins further manipulate the create table query
                 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_befe.php']['deleteProductPreHook'])) {
                     $params = array('products_id' => $products_id, 'categories_id' => &$categories_id);
                     foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_befe.php']['deleteProductPreHook'] as $funcRef) {
                         \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
                     }
                 }
                 for ($x = 0; $x < $this->ms['MODULES']['NUMBER_OF_PRODUCT_IMAGES']; $x++) {
                     $i = $x;
                     if ($i == 0) {
                         $i = '';
                     }
                     $filename = $productRow['products_image' . $i];
                     if ($filename) {
                         $orFilter = array();
                         for ($i = 0; $i < $this->ms['MODULES']['NUMBER_OF_PRODUCT_IMAGES']; $i++) {
                             $s = '';
                             if ($i > 0) {
                                 $s = $i;
                             }
                             $orFilter[] = 'products_image' . $s . '=\'' . addslashes($filename) . '\'';
                         }
                         $filter = array();
                         $filter[] = '(' . implode(' OR ', $orFilter) . ')';
                         $count = mslib_befe::getCount('', 'tx_multishop_products', '', $filter);
                         if ($count < 2) {
                             // Only delete the file is we have found 1 product using it
                             mslib_befe::deleteProductImage($filename);
                         }
                     }
                 }
                 $tables = array();
                 $tables[] = 'tx_multishop_products';
                 if ($this->ms['MODULES']['FLAT_DATABASE']) {
                     $tables[] = 'tx_multishop_products_flat';
                 }
                 $tables[] = 'tx_multishop_products_description';
                 $tables[] = 'tx_multishop_products_to_categories';
                 $tables[] = 'tx_multishop_products_attributes';
                 $tables[] = 'tx_multishop_specials';
                 $tables[] = 'tx_multishop_undo_products';
                 $tables[] = 'tx_multishop_products_faq';
                 $tables[] = 'tx_multishop_products_to_extra_options';
                 foreach ($tables as $table) {
                     if ($use_page_uid) {
                         if ($table == 'tx_multishop_products' || $table == 'tx_multishop_products_description' || $table == 'tx_multishop_products_to_categories' || $table == 'tx_multishop_products_attributes') {
                             $query = $GLOBALS['TYPO3_DB']->DELETEquery($table, 'products_id=' . $products_id . ' and page_uid=\'' . $this->shop_pid . '\'');
                         }
                     } else {
                         $query = $GLOBALS['TYPO3_DB']->DELETEquery($table, 'products_id=' . $products_id);
                     }
                     $res = $GLOBALS['TYPO3_DB']->sql_query($query);
                 }
                 $qry = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_multishop_products_to_relative_products', 'products_id=' . $products_id . ' or relative_product_id=' . $products_id);
                 //hook to let other plugins further manipulate the create table query
                 if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_befe.php']['deleteProductPostHook'])) {
                     $params = array('products_id' => $products_id);
                     foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/pi1/classes/class.mslib_befe.php']['deleteProductPostHook'] as $funcRef) {
                         \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
                     }
                 }
                 return 1;
             }
         }
     }
 }
Exemple #2
0
 $image_array_key = "products_image" . $img_counter;
 $image_filename = $this->post['image_filename'];
 $orFilter = array();
 for ($i = 0; $i < $this->ms['MODULES']['NUMBER_OF_PRODUCT_IMAGES']; $i++) {
     $s = '';
     if ($i > 0) {
         $s = $i;
     }
     $orFilter[] = 'products_image' . $s . '=\'' . addslashes($image_filename) . '\'';
 }
 $filter = array();
 $filter[] = '(' . implode(' OR ', $orFilter) . ')';
 $count = mslib_befe::getCount('', 'tx_multishop_products', '', $filter);
 if ($count < 2) {
     // Only delete the file is we have found 1 product using it
     mslib_befe::deleteProductImage($image_filename);
 }
 if (is_numeric($pid) && $pid > 0) {
     $updateArray = array();
     $updateArray[$image_array_key] = '';
     if ($image_array_key == 'products_image') {
         $updateArray['contains_image'] = 0;
     }
     $query = $GLOBALS['TYPO3_DB']->UPDATEquery('tx_multishop_products', 'products_id=\'' . $pid . '\'', $updateArray);
     $res = $GLOBALS['TYPO3_DB']->sql_query($query);
 }
 if ($this->ms['MODULES']['ADMIN_CROP_PRODUCT_IMAGES']) {
     if (is_numeric($pid) && $pid > 0) {
         $qry = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_multishop_product_crop_image_coordinate', 'image_filename=\'' . addslashes($image_filename) . '\' and products_id=\'' . $pid . '\'');
     } else {
         $qry = $GLOBALS['TYPO3_DB']->exec_DELETEquery('tx_multishop_product_crop_image_coordinate', 'image_filename=\'' . addslashes($image_filename) . '\'');