foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/includes/admin_edit_product.php']['insertProductPostHook'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } // custom hook that can be controlled by third-party plugin eof } if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/admin_edit_product.php']['saveProductPostHook'])) { $params = array('prodid' => $prodid); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/admin_edit_product.php']['saveProductPostHook'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } // set default Crumpath mslib_befe::setProductDefaultCrumpath($prodid); // lets notify plugin that we have update action in product tx_mslib_catalog::productsUpdateNotifierForPlugin($this->post, $prodid); // custom hook that can be controlled by third-party plugin eof if ($this->ms['MODULES']['FLAT_DATABASE']) { // if the flat database module is enabled we have to sync the changes to the flat table mslib_befe::convertProductToFlat($prodid); } if (isset($this->post['SaveClose']) || isset($this->post['save_as_new'])) { if (strpos($this->post['tx_multishop_pi1']['referrer'], 'action=edit_product') === false && strpos($this->post['tx_multishop_pi1']['referrer'], 'action=add_product') === false && $this->post['tx_multishop_pi1']['referrer']) { header("Location: " . $this->post['tx_multishop_pi1']['referrer']); exit; } else { header("Location: " . $this->FULL_HTTP_URL . mslib_fe::typolink($this->shop_pid . ',2003', 'tx_multishop_pi1[page_section]=admin_products_search_and_edit', 1)); exit; } } else { if (isset($this->post['Submit'])) {
function compareDatabaseRebuildProductsToCategoryTree($pid, $deepest_cat_id, $dataArray = array()) { if (!is_numeric($pid)) { return false; } if (!is_numeric($deepest_cat_id)) { return false; } $level = 1; $cats = mslib_fe::globalCrumbarTree($deepest_cat_id); $cats = array_reverse($cats); // $crumbar_ident_string = ''; $crumbar_ident_array = array(); foreach ($cats as $item) { $crumbar_ident_array[] = $item['id']; } $crumbar_ident_string = implode(',', $crumbar_ident_array); $count_cats = count($cats); /*if ($count_cats>1) { // remove the deepest cat id record // disabled by bas //unset($cats[$count_cats-1]); //recount //$count_cats=count($cats); }*/ if ($count_cats > 0) { foreach ($cats as $item) { if ($item['id']) { $rec = tx_mslib_catalog::isProductToCategoryLinkingExist($pid, $item['id'], $crumbar_ident_string); if (!$rec) { $insertArray = array(); if (!is_array($dataArray) || is_array($dataArray) && !count($dataArray)) { $insertArray['categories_id'] = $deepest_cat_id; $insertArray['products_id'] = $pid; $insertArray['page_uid'] = $item['page_uid']; $insertArray['sort_order'] = time(); $insertArray['related_to'] = 0; } else { foreach ($dataArray as $idx => $val) { $insertArray[$idx] = $val; } } $insertArray['node_id'] = $item['id']; if ($item['id'] == $deepest_cat_id) { $insertArray['is_deepest'] = 1; } else { $insertArray['is_deepest'] = 0; } $insertArray['crumbar_identifier'] = $crumbar_ident_string; $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_to_categories', $insertArray); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } else { $updateArray = array(); if (!empty($rec['crumbar_identifier'])) { $tmp_cid = explode(',', $rec['crumbar_identifier']); $last_index = count($tmp_cid) - 1; if ($tmp_cid[$last_index] == $deepest_cat_id) { if ($item['id'] == $deepest_cat_id) { $updateArray['is_deepest'] = 1; } else { $updateArray['is_deepest'] = 0; } $updateArray['crumbar_identifier'] = $crumbar_ident_string; $query = $GLOBALS['TYPO3_DB']->UPDATEquery('tx_multishop_products_to_categories', 'products_to_categories_id=\'' . $rec['products_to_categories_id'] . '\'', $updateArray); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } else { if ($item['id'] == $deepest_cat_id) { $updateArray['is_deepest'] = 1; } else { $updateArray['is_deepest'] = 0; } $updateArray['crumbar_identifier'] = $crumbar_ident_string; $query = $GLOBALS['TYPO3_DB']->UPDATEquery('tx_multishop_products_to_categories', 'products_to_categories_id=\'' . $rec['products_to_categories_id'] . '\'', $updateArray); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } $level++; /*if ($pid==508) { echo "<pre>"; var_dump($query); echo "<br/>"; }*/ } } //return true; } }
public function duplicateProduct($id_product, $target_categories_id) { if (!is_numeric($id_product)) { return false; } if (!is_numeric($target_categories_id)) { return false; } $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products', 'products_id=\'' . $id_product . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry) == 0) { return false; } else { //insert into tx_multishop_products $row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry); $product_arr_new = array(); if (is_array($row) && count($row)) { foreach ($row as $key_p => $val_p) { if ($key_p != 'products_id') { if ($key_p == 'products_image' or $key_p == 'products_image1' or $key_p == 'products_image2' or $key_p == 'products_image3' or $key_p == 'products_image4') { if (!empty($val_p)) { $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products_description', 'products_id=\'' . $id_product . '\' and language_id=\'' . $this->sys_language_uid . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); $row_desc = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry); $file = mslib_befe::getImagePath($val_p, 'products', 'original'); //echo $file; $imgtype = mslib_befe::exif_imagetype($file); if ($imgtype) { // valid image $ext = image_type_to_extension($imgtype, false); if ($ext) { $i = 0; $filename = mslib_fe::rewritenamein($row_desc['products_name']) . '.' . $ext; //echo $filename; $folder = mslib_befe::getImagePrefixFolder($filename); $array = explode(".", $filename); if (!is_dir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder); } $folder .= '/'; $target = $this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder . $filename; //echo $target; if (file_exists($target)) { do { $filename = mslib_fe::rewritenamein($row_desc['products_name']) . ($i > 0 ? '-' . $i : '') . '.' . $ext; $folder_name = mslib_befe::getImagePrefixFolder($filename); $array = explode(".", $filename); $folder = $folder_name; if (!is_dir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder)) { \TYPO3\CMS\Core\Utility\GeneralUtility::mkdir($this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder); } $folder .= '/'; $target = $this->DOCUMENT_ROOT . $this->ms['image_paths']['products']['original'] . '/' . $folder . $filename; $i++; //echo $target . "<br/>"; } while (file_exists($target)); } if (copy($file, $target)) { $target_origineel = $target; $update_product_images = mslib_befe::resizeProductImage($target_origineel, $filename, $this->DOCUMENT_ROOT . \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::siteRelPath($this->extKey)); } } } $product_arr_new[$key_p] = $update_product_images; } else { $product_arr_new[$key_p] = $val_p; } } else { $product_arr_new[$key_p] = $val_p; } } } } $product_arr_new['sort_order'] = time(); $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); $id_product_new = $GLOBALS['TYPO3_DB']->sql_insert_id(); unset($product_arr_new); if ($id_product_new) { // insert tx_multishop_products_description $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products_description', 'products_id=\'' . $id_product . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) { $product_arr_new = $row; $product_arr_new['products_id'] = $id_product_new; if (strpos($product_arr_new['products_name'], '(copy') === false) { $product_arr_new['products_name'] .= ' (copy ' . $id_product_new . ')'; } else { if (strpos($product_arr_new['products_name'], '(copy ' . $id_product . ')') !== false) { $product_arr_new['products_name'] = str_replace('(copy ' . $id_product . ')', ' (copy ' . $id_product_new . ')', $product_arr_new['products_name']); } else { $product_arr_new['products_name'] = str_replace('(copy)', ' (copy ' . $id_product_new . ')', $product_arr_new['products_name']); } } $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_description', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } // insert tx_multishop_products_attributes $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products_attributes', 'products_id=\'' . $id_product . '\' and page_uid=\'' . $this->showCatalogFromPage . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry) > 0) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) { $product_arr_new = $row; $product_arr_new['products_id'] = $id_product_new; $product_arr_new['page_uid'] = $this->showCatalogFromPage; unset($product_arr_new['products_attributes_id']); //primary key $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_attributes', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } // insert tx_multishop_specials $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_specials', 'products_id=\'' . $id_product . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry) > 0) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) { $product_arr_new = $row; $product_arr_new['products_id'] = $id_product_new; unset($product_arr_new['specials_id']); //primary key $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_specials', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } // insert tx_multishop_products_to_relative_products $str = $GLOBALS['TYPO3_DB']->SELECTquery('*', 'tx_multishop_products_to_relative_products', 'products_id=\'' . $id_product . '\' or relative_product_id = \'' . $id_product . '\'', '', '', ''); $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if ($GLOBALS['TYPO3_DB']->sql_num_rows($qry) > 0) { while ($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) { $product_arr_new = $row; if ($product_arr_new['products_id'] == $id_product) { $product_arr_new['products_id'] = $id_product_new; } else { $product_arr_new['relative_product_id'] = $id_product_new; } unset($product_arr_new['products_to_relative_product_id']); //primary key $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_to_relative_products', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } // insert into tx_multishop_products_to_categories $insertArray = array('products_id' => $id_product_new, 'categories_id' => $target_categories_id, 'sort_order' => time(), 'page_uid' => $this->showCatalogFromPage); //$query=$GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_to_categories', $insertArray); //$res=$GLOBALS['TYPO3_DB']->sql_query($query); // create categories tree linking $res = tx_mslib_catalog::linkCategoriesTreeToProduct($id_product_new, $target_categories_id, $insertArray); if ($res) { if ($this->ms['MODULES']['FLAT_DATABASE']) { mslib_befe::convertProductToFlat($id_product); } } else { return false; } } } }
$insertArray['foreign_categories_id'] = $foreign_cat_id; $insertArray['page_uid'] = $this->showCatalogFromPage; $insertArray['foreign_page_uid'] = $page_uid; $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_categories_to_categories', $insertArray); $res = $GLOBALS['TYPO3_DB']->sql_query($query); $has_products = mslib_fe::getProducts('', $catid); if (count($has_products)) { foreach ($has_products as $product_id => $product_data) { $updateArray = array(); $updateArray['categories_id'] = $foreign_cat_id; $updateArray['products_id'] = $product_id; $updateArray['sort_order'] = time(); $updateArray['page_uid'] = $page_uid; $updateArray['related_to'] = $reflector_cattree[$foreign_cat_id]; // create categories tree linking tx_mslib_catalog::linkCategoriesTreeToProduct($product_id, $foreign_cat_id, $updateArray); } } } } } } else { if ($_REQUEST['action'] == 'edit_category') { // update name only on other shop $str = "SELECT c.categories_id from tx_multishop_categories c where c.related_to='" . $catid . "'"; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); if (!$GLOBALS['TYPO3_DB']->sql_num_rows($qry)) { // update name only on other shop $str = "SELECT p2c.categories_id from tx_multishop_products_to_categories p2c where p2c.related_to='" . $catid . "' group by categories_id"; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); }
$product_arr_new['products_id'] = $id_product_new; } else { $product_arr_new['relative_product_id'] = $id_product_new; } unset($product_arr_new['products_to_relative_product_id']); //primary key $query = $GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_to_relative_products', $product_arr_new); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } } // insert into tx_multishop_products_to_categories $insertArray = array('products_id' => $id_product_new, 'categories_id' => $id_category, 'page_uid' => $this->showCatalogFromPage, 'sort_order' => time()); //$query=$GLOBALS['TYPO3_DB']->INSERTquery('tx_multishop_products_to_categories', $insertArray); //$res=$GLOBALS['TYPO3_DB']->sql_query($query); // create categories tree linking $res = tx_mslib_catalog::linkCategoriesTreeToProduct($id_product_new, $id_category, $insertArray); // custom page hook that can be controlled by third-party plugin if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/ajax_pages/copy_duplicate_product.php']['copyDuplicateProductPostHook'])) { $params = array('old_products_id' => &$id_product, 'products_id' => &$id_product_new); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/ajax_pages/copy_duplicate_product.php']['copyDuplicateProductPostHook'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } // custom page hook that can be controlled by third-party plugin eof if ($res) { echo "<p>Product succesfully duplicated</p>"; if ($this->ms['MODULES']['FLAT_DATABASE']) { // if the flat database module is enabled we have to sync the changes to the flat table mslib_befe::convertProductToFlat($id_product_new); } } else {
} } } } } // update flat database if ($this->ms['MODULES']['FLAT_DATABASE'] or $this->ms['MODULES']['GLOBAL_MODULES']['FLAT_DATABASE']) { if (isset($item['products_status']) and $item['products_status'] == '0' and is_numeric($products_id)) { $query = $GLOBALS['TYPO3_DB']->DELETEquery('tx_multishop_products_flat', 'products_id=' . $products_id); $res = $GLOBALS['TYPO3_DB']->sql_query($query); } else { mslib_befe::convertProductToFlat($products_id, 'tx_multishop_products_flat'); } } // lets notify plugin that we have update action in product tx_mslib_catalog::productsUpdateNotifierForPlugin($item); // update flat database eof if ($item['added_products_id']) { // custom hook that can be controlled by third-party plugin if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/admin_import.php']['insertProductPostHook'])) { $params = array('products_id' => $item['added_products_id'], 'item' => &$item, 'prefix_source_name' => $this->post['prefix_source_name']); foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/admin_import.php']['insertProductPostHook'] as $funcRef) { \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this); } } // custom hook that can be controlled by third-party plugin eof // set default Crumpath mslib_befe::setProductDefaultCrumpath($item['added_products_id']); } elseif ($item['updated_products_id']) { // custom hook that can be controlled by third-party plugin if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/admin_import.php']['updateProductPostHook'])) {
$str = "UPDATE `tx_multishop_products_to_categories` SET `current_relation`=1"; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); // rebuild the p2c link tx_mslib_catalog::compareDatabaseAlterProductToCategoryLinking(); // remove the entry $str = "DELETE FROM `tx_multishop_products_to_categories` WHERE `current_relation`=1"; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); // remove the col $str = "ALTER TABLE `tx_multishop_products_to_categories` DROP `current_relation`"; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); } } } } else { // method to fix the broken linking of product to categories $p2c_fix_msg = tx_mslib_catalog::compareDatabaseFixProductToCategoryLinking(); if (!empty($p2c_fix_msg)) { $messages[] = $p2c_fix_msg; } } $str = "describe tx_multishop_cms"; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) != false) { if ($row['Field'] == 'id') { if ($row['Extra'] != 'auto_increment') { $str = "DELETE FROM `tx_multishop_cms` WHERE `id`=0"; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); $messages[] = $str; $str = "ALTER TABLE `tx_multishop_cms` CHANGE `id` `id` INT( 11 ) null auto_increment;"; $qry = $GLOBALS['TYPO3_DB']->sql_query($str); $messages[] = $str;
case 'products_price': $content .= tx_mslib_catalog::sortCatalog($this->get['tx_multishop_pi1']['sortItem'], $this->get['tx_multishop_pi1']['sortByField'], $this->get['tx_multishop_pi1']['orderBy']); break; case 'products_date_added': $content .= tx_mslib_catalog::sortCatalog($this->get['tx_multishop_pi1']['sortItem'], $this->get['tx_multishop_pi1']['sortByField'], $this->get['tx_multishop_pi1']['orderBy']); break; case 'products_main_categories': $content .= tx_mslib_catalog::sortCatalog($this->get['tx_multishop_pi1']['sortItem'], $this->get['tx_multishop_pi1']['sortByField'], $this->get['tx_multishop_pi1']['orderBy']); break; case 'products_deepest_categories': $content .= tx_mslib_catalog::sortCatalog($this->get['tx_multishop_pi1']['sortItem'], $this->get['tx_multishop_pi1']['sortByField'], $this->get['tx_multishop_pi1']['orderBy']); break; } break; case 'attribute_values': switch ($this->get['tx_multishop_pi1']['sortByField']) { case 'products_options_values_name': case 'products_options_values_name_natural': $content .= tx_mslib_catalog::sortCatalog($this->get['tx_multishop_pi1']['sortItem'], $this->get['tx_multishop_pi1']['sortByField'], $this->get['tx_multishop_pi1']['orderBy']); break; } break; case 'attribute_names': switch ($this->get['tx_multishop_pi1']['sortByField']) { case 'products_options_name': case 'products_options_name_natural': $content .= tx_mslib_catalog::sortCatalog($this->get['tx_multishop_pi1']['sortItem'], $this->get['tx_multishop_pi1']['sortByField'], $this->get['tx_multishop_pi1']['orderBy']); break; } break; }