function quick_copy_product($products_id, $categories_id = '') { global $db; if (!(isset($products_id) && isset($categories_id))) { return FALSE; } // ?? $products_id = (int) $products_id; // copy from this product (to a new product) //$categories_id = zen_db_prepare_input($categories_id); // copy to this catagory //if(!($products_id > 0)) return false; if (!zen_products_id_valid($products_id)) { exit('Fatal error: attempt to copy invalid product by quick_copy (products_id = ' . $products_id . ')'); } // Copy attributes to duplicate product $products_id_from = $products_id; // bof duplicate $old_products_id = (int) $products_id; $product = $db->Execute("select products_type, products_quantity, products_model, products_image,\r\n products_price, products_virtual, products_date_available, products_weight,\r\n products_tax_class_id, manufacturers_id,\r\n products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute,\r\n product_is_free, product_is_call, products_quantity_mixed,\r\n product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order,\r\n products_price_sorter, master_categories_id\r\n from " . TABLE_PRODUCTS . "\r\n where products_id = '" . (int) $products_id . "'"); // bof replace product data by nimport product data (+ add purchase price) // eof replace product data by nimport product data $tmp_value = zen_db_input($product->fields['products_quantity']); $products_quantity = !zen_not_null($tmp_value) || $tmp_value == '' || $tmp_value == 0 ? 0 : $tmp_value; $tmp_value = zen_db_input($product->fields['products_price']); $products_price = !zen_not_null($tmp_value) || $tmp_value == '' || $tmp_value == 0 ? 0 : $tmp_value; $tmp_value = zen_db_input($product->fields['products_weight']); $products_weight = !zen_not_null($tmp_value) || $tmp_value == '' || $tmp_value == 0 ? 0 : $tmp_value; // check if categorie has products!? if (!$categories_id >= 0) { $categories_id = $product->fields['master_categories_id']; } $db->Execute("insert into " . TABLE_PRODUCTS . "\r\n (products_type, products_quantity, products_model, products_image,\r\n products_price, products_virtual, products_date_added, products_date_available,\r\n products_weight, products_status, products_tax_class_id,\r\n manufacturers_id,\r\n products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute,\r\n product_is_free, product_is_call, products_quantity_mixed,\r\n product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order,\r\n products_price_sorter, master_categories_id\r\n )\r\n values ('" . zen_db_input($product->fields['products_type']) . "',\r\n '" . $products_quantity . "',\r\n '" . zen_db_input($product->fields['products_model']) . "',\r\n '" . zen_db_input($product->fields['products_image']) . "',\r\n '" . $products_price . "',\r\n '" . zen_db_input($product->fields['products_virtual']) . "',\r\n now(),\r\n '" . zen_db_input($product->fields['products_date_available']) . "',\r\n '" . $products_weight . "', '0',\r\n '" . (int) $product->fields['products_tax_class_id'] . "',\r\n '" . (int) $product->fields['manufacturers_id'] . "',\r\n '" . zen_db_input($product->fields['products_quantity_order_min']) . "',\r\n '" . zen_db_input($product->fields['products_quantity_order_units']) . "',\r\n '" . zen_db_input($product->fields['products_priced_by_attribute']) . "',\r\n '" . (int) $product->fields['product_is_free'] . "',\r\n '" . (int) $product->fields['product_is_call'] . "',\r\n '" . (int) $product->fields['products_quantity_mixed'] . "',\r\n '" . zen_db_input($product->fields['product_is_always_free_shipping']) . "',\r\n '" . zen_db_input($product->fields['products_qty_box_status']) . "',\r\n '" . zen_db_input($product->fields['products_quantity_order_max']) . "',\r\n '" . zen_db_input($product->fields['products_sort_order']) . "',\r\n '" . zen_db_input($product->fields['products_price_sorter']) . "',\r\n '" . (int) $categories_id . "')"); $dup_products_id = $db->Insert_ID(); $description = $db->Execute("select language_id, products_name, products_description, products_url\r\n from " . TABLE_PRODUCTS_DESCRIPTION . "\r\n where products_id = '" . (int) $products_id . "'"); while (!$description->EOF) { $db->Execute("insert into " . TABLE_PRODUCTS_DESCRIPTION . "\r\n (products_id, language_id, products_name, products_description, products_url, products_viewed)\r\n values ('" . (int) $dup_products_id . "',\r\n '" . (int) $description->fields['language_id'] . "',\r\n '" . zen_db_input($description->fields['products_name']) . "',\r\n '" . zen_db_input($description->fields['products_description']) . "',\r\n '" . zen_db_input($description->fields['products_url']) . "', '0')"); $description->MoveNext(); } $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "\r\n (products_id, categories_id)\r\n values ('" . (int) $dup_products_id . "', '" . (int) $categories_id . "')"); $products_id = $dup_products_id; $description->MoveNext(); // FIX HERE ///////////////////////////////////////////////////////////////////////////////////////////// // Copy attributes to duplicate product $products_id_to = $dup_products_id; $products_id = $dup_products_id; /* if ( $_POST['copy_attributes']=='copy_attributes_yes' and $_POST['copy_as'] == 'duplicate' ) { // $products_id_to= $copy_to_products_id; // $copy_attributes_delete_first='1'; // $copy_attributes_duplicates_skipped='1'; // $copy_attributes_duplicates_overwrite='0'; if (DOWNLOAD_ENABLED == 'true') { $copy_attributes_include_downloads='1'; $copy_attributes_include_filename='1'; } else { $copy_attributes_include_downloads='0'; $copy_attributes_include_filename='0'; } zen_copy_products_attributes($products_id_from, $products_id_to); } */ // EOF: Attributes Copy on non-linked ///////////////////////////////////////////////////////////////////// // copy product discounts to duplicate zen_copy_discounts_to_product($old_products_id, (int) $dup_products_id); // eof duplicate // reset products_price_sorter for searches etc. zen_update_products_price_sorter($products_id); //zen_redirect(zen_href_link(FILENAME_QUICK_COPY, 'cPath=' . $categories_id . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : ''))); // succes $copy['products_id'] = (int) $dup_products_id; $copy['master_categories_id'] = (int) $categories_id; return $copy; }
///////////////////////////////////////////////////////////////////////////////////////////// // Copy attributes to duplicate product // moved above $products_id_from=zen_db_input($products_id); $products_id_to = $dup_products_id; $products_id = $dup_products_id; if ($_POST['copy_attributes'] == 'copy_attributes_yes' and $_POST['copy_as'] == 'duplicate') { // $products_id_to= $copy_to_products_id; // $products_id_from = $pID; // $copy_attributes_delete_first='1'; // $copy_attributes_duplicates_skipped='1'; // $copy_attributes_duplicates_overwrite='0'; if (DOWNLOAD_ENABLED == 'true') { $copy_attributes_include_downloads = '1'; $copy_attributes_include_filename = '1'; } else { $copy_attributes_include_downloads = '0'; $copy_attributes_include_filename = '0'; } zen_copy_products_attributes($products_id_from, $products_id_to); } // EOF: Attributes Copy on non-linked ///////////////////////////////////////////////////////////////////// // copy product discounts to duplicate if ($_POST['copy_discounts'] == 'copy_discounts_yes') { zen_copy_discounts_to_product($old_products_id, (int) $dup_products_id); } } // reset products_price_sorter for searches etc. zen_update_products_price_sorter($products_id); } zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $categories_id . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')));