ZenCart_Documentation  1.5.0
http://www.collinsharper.com
C:/xampp/htdocs/zen-cart/admin/includes/modules/product_music/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             if (isset($_POST['copy_media']) && $_POST['copy_media'] == 'on') {
00090               $product_media = $db->Execute("select media_id from " . TABLE_MEDIA_TO_PRODUCTS . "
00091                                              where product_id = '" . (int)$products_id . "'");
00092               while (!$product_media->EOF) {
00093                 $db->Execute("insert into " . TABLE_MEDIA_TO_PRODUCTS . "
00094                               (media_id, product_id)
00095                               values (
00096                               '" . $product_media->fields['media_id'] . "',
00097                               '" . $dup_products_id . "')");
00098                 $product_media->MoveNext();
00099               }
00100             }
00101 
00102             $music_extra = $db->Execute("select artists_id, record_company_id, music_genre_id from " . TABLE_PRODUCT_MUSIC_EXTRA . "                                                where products_id = '" . (int)$products_id . "'");
00103 
00104             $db->Execute("insert into " . TABLE_PRODUCT_MUSIC_EXTRA . "
00105                           (products_id, artists_id, record_company_id, music_genre_id)
00106                           values (
00107                          '" . (int)$dup_products_id . "',
00108                          '" . zen_db_input($music_extra->fields['artists_id']) . "',
00109                          '" . zen_db_input($music_extra->fields['record_company_id']) . "',
00110                          '" . zen_db_input($music_extra->fields['music_genre_id']) . "')");
00111 
00112 
00113             $description = $db->Execute("select language_id, products_name, products_description,
00114                                                              products_url
00115                                          from " . TABLE_PRODUCTS_DESCRIPTION . "
00116                                          where products_id = '" . (int)$products_id . "'");
00117             while (!$description->EOF) {
00118               $db->Execute("insert into " . TABLE_PRODUCTS_DESCRIPTION . "
00119                                         (products_id, language_id, products_name, products_description,
00120                                          products_url, products_viewed)
00121                             values ('" . (int)$dup_products_id . "',
00122                                     '" . (int)$description->fields['language_id'] . "',
00123                                     '" . zen_db_input($description->fields['products_name']) . "',
00124                                     '" . zen_db_input($description->fields['products_description']) . "',
00125                                     '" . zen_db_input($description->fields['products_url']) . "', '0')");
00126               $description->MoveNext();
00127             }
00128 
00129             $db->Execute("insert into " . TABLE_PRODUCTS_TO_CATEGORIES . "
00130                           (products_id, categories_id)
00131                           values ('" . (int)$dup_products_id . "', '" . (int)$categories_id . "')");
00132             $products_id = $dup_products_id;
00133             $description->MoveNext();
00134 // FIX HERE
00136 // Copy attributes to duplicate product
00137 // moved above            $products_id_from=zen_db_input($products_id);
00138             $products_id_to= $dup_products_id;
00139             $products_id = $dup_products_id;
00140 
00141 if ( $_POST['copy_attributes']=='copy_attributes_yes' and $_POST['copy_as'] == 'duplicate' ) {
00142   // $products_id_to= $copy_to_products_id;
00143   // $products_id_from = $pID;
00144 //            $copy_attributes_delete_first='1';
00145 //            $copy_attributes_duplicates_skipped='1';
00146 //            $copy_attributes_duplicates_overwrite='0';
00147 
00148             if (DOWNLOAD_ENABLED == 'true') {
00149               $copy_attributes_include_downloads='1';
00150               $copy_attributes_include_filename='1';
00151             } else {
00152               $copy_attributes_include_downloads='0';
00153               $copy_attributes_include_filename='0';
00154             }
00155 
00156             zen_copy_products_attributes($products_id_from, $products_id_to);
00157 }
00158 // EOF: Attributes Copy on non-linked
00160 
00161             // copy product discounts to duplicate
00162             if ($_POST['copy_discounts'] == 'copy_discounts_yes') {
00163               zen_copy_discounts_to_product($old_products_id, (int)$dup_products_id);
00164             }
00165 
00166           }
00167 
00168           // reset products_price_sorter for searches etc.
00169           zen_update_products_price_sorter($products_id);
00170 
00171         }
00172         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