ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/modules/copy_to_confirm.php
Go to the documentation of this file.
00001 <?php
00009 if (!defined('IS_ADMIN_FLAG')) {
00010   die('Illegal Access');
00011 }
00012         if (isset($_POST['products_id']) && isset($_POST['categories_id'])) {
00013           $products_id = zen_db_prepare_input($_POST['products_id']);
00014           $categories_id = zen_db_prepare_input($_POST['categories_id']);
00015 
00016 // Copy attributes to duplicate product
00017           $products_id_from=$products_id;
00018 
00019           if ($_POST['copy_as'] == 'link') {
00020             if ($categories_id != $current_category_id) {
00021               $check = $db->Execute("select count(*) as total
00022                                      from " . TABLE_PRODUCTS_TO_CATEGORIES . "
00023                                      where products_id = '" . (int)$products_id . "'
00024                                      and categories_id = '" . (int)$categories_id . "'");
00025               if ($check->fields['total'] < '1') {
00026                 $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
00027                                           (products_id, categories_id)
00028                               values ('" . (int)$products_id . "', '" . (int)$categories_id . "')");
00029               }
00030             } else {
00031               $messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_CATEGORY, 'error');
00032             }
00033           } elseif ($_POST['copy_as'] == 'duplicate') {
00034             $old_products_id = (int)$products_id;
00035             $product = $db->Execute("select products_type, products_quantity, products_model, products_image,
00036                                             products_price, products_virtual, products_date_available, products_weight,
00037                                             products_tax_class_id, manufacturers_id,
00038                                             products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute,
00039                                             product_is_free, product_is_call, products_quantity_mixed,
00040                                             product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order,
00041                                             products_price_sorter, master_categories_id
00042                                      from " . TABLE_PRODUCTS . "
00043                                      where products_id = '" . (int)$products_id . "'");
00044 
00045             $tmp_value = zen_db_input($product->fields['products_quantity']);
00046             $products_quantity = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
00047             $tmp_value = zen_db_input($product->fields['products_price']);
00048             $products_price = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
00049             $tmp_value = zen_db_input($product->fields['products_weight']);
00050             $products_weight = (!zen_not_null($tmp_value) || $tmp_value=='' || $tmp_value == 0) ? 0 : $tmp_value;
00051 
00052             $db->Execute("insert into " . TABLE_PRODUCTS . "
00053                                       (products_type, products_quantity, products_model, products_image,
00054                                        products_price, products_virtual, products_date_added, products_date_available,
00055                                        products_weight, products_status, products_tax_class_id,
00056                                        manufacturers_id,
00057                                        products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute,
00058                                        product_is_free, product_is_call, products_quantity_mixed,
00059                                        product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order,
00060                                        products_price_sorter, master_categories_id
00061                                        )
00062                           values ('" . zen_db_input($product->fields['products_type']) . "',
00063                                   '" . $products_quantity . "',
00064                                   '" . zen_db_input($product->fields['products_model']) . "',
00065                                   '" . zen_db_input($product->fields['products_image']) . "',
00066                                   '" . $products_price . "',
00067                                   '" . zen_db_input($product->fields['products_virtual']) . "',
00068                                   now(),
00069                                   '" . (zen_not_null(zen_db_input($product->fields['products_date_available'])) ? zen_db_input($product->fields['products_date_available']) : '0001-01-01 00:00:00') . "',
00070                                   '" . $products_weight . "', '0',
00071                                   '" . (int)$product->fields['products_tax_class_id'] . "',
00072                                   '" . (int)$product->fields['manufacturers_id'] . "',
00073                                   '" . zen_db_input($product->fields['products_quantity_order_min']) . "',
00074                                   '" . zen_db_input($product->fields['products_quantity_order_units']) . "',
00075                                   '" . zen_db_input($product->fields['products_priced_by_attribute']) . "',
00076                                   '" . (int)$product->fields['product_is_free'] . "',
00077                                   '" . (int)$product->fields['product_is_call'] . "',
00078                                   '" . (int)$product->fields['products_quantity_mixed'] . "',
00079                                   '" . zen_db_input($product->fields['product_is_always_free_shipping']) . "',
00080                                   '" . zen_db_input($product->fields['products_qty_box_status']) . "',
00081                                   '" . zen_db_input($product->fields['products_quantity_order_max']) . "',
00082                                   '" . zen_db_input($product->fields['products_sort_order']) . "',
00083                                   '" . zen_db_input($product->fields['products_price_sorter']) . "',
00084                                   '" . zen_db_input($categories_id) .
00085                                   "')");
00086 
00087             $dup_products_id = $db->Insert_ID();
00088 
00089             $description = $db->Execute("select language_id, products_name, products_description,
00090                                                              products_url
00091                                          from " . TABLE_PRODUCTS_DESCRIPTION . "
00092                                          where products_id = '" . (int)$products_id . "'");
00093             while (!$description->EOF) {
00094               $db->Execute("insert into " . TABLE_PRODUCTS_DESCRIPTION . "
00095                                         (products_id, language_id, products_name, products_description,
00096                                          products_url, products_viewed)
00097                             values ('" . (int)$dup_products_id . "',
00098                                     '" . (int)$description->fields['language_id'] . "',
00099                                     '" . zen_db_input($description->fields['products_name']) . "',
00100                                     '" . zen_db_input($description->fields['products_description']) . "',
00101                                     '" . zen_db_input($description->fields['products_url']) . "', '0')");
00102               $description->MoveNext();
00103             }
00104 
00105             $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
00106                           (products_id, categories_id)
00107                           values ('" . (int)$dup_products_id . "', '" . (int)$categories_id . "')");
00108             $products_id = $dup_products_id;
00109             $description->MoveNext();
00110 // FIX HERE
00112 // Copy attributes to duplicate product
00113 // moved above            $products_id_from=zen_db_input($products_id);
00114             $products_id_to= $dup_products_id;
00115             $products_id = $dup_products_id;
00116 
00117 if ( $_POST['copy_attributes']=='copy_attributes_yes' and $_POST['copy_as'] == 'duplicate' ) {
00118   // $products_id_to= $copy_to_products_id;
00119   // $products_id_from = $pID;
00120 //            $copy_attributes_delete_first='1';
00121 //            $copy_attributes_duplicates_skipped='1';
00122 //            $copy_attributes_duplicates_overwrite='0';
00123 
00124             if (DOWNLOAD_ENABLED == 'true') {
00125               $copy_attributes_include_downloads='1';
00126               $copy_attributes_include_filename='1';
00127             } else {
00128               $copy_attributes_include_downloads='0';
00129               $copy_attributes_include_filename='0';
00130             }
00131 
00132             zen_copy_products_attributes($products_id_from, $products_id_to);
00133 }
00134 // EOF: Attributes Copy on non-linked
00136 
00137             // copy product discounts to duplicate
00138             if ($_POST['copy_discounts'] == 'copy_discounts_yes') {
00139               zen_copy_discounts_to_product($old_products_id, (int)$dup_products_id);
00140             }
00141 
00142           }
00143 
00144           // reset products_price_sorter for searches etc.
00145           zen_update_products_price_sorter($products_id);
00146 
00147         }
00148         zen_redirect(zen_href_link(FILENAME_CATEGORIES, 'cPath=' . $categories_id . '&pID=' . $products_id . (isset($_GET['page']) ? '&page=' . $_GET['page'] : '')));
 All Data Structures Namespaces Files Functions Variables Enumerations