Page 1 of 2 12 LastLast
Results 1 to 10 of 13
  1. #1
    Join Date
    Jul 2016
    Posts
    59
    Plugin Contributions
    0

    Default Error on duplicating product

    Just set up a new version of my shop (ledsales.com.au) using 1.5.8a and has been working quite well. However, today I tried to duplicate a product, which also has qty discounts and links into other categories, and got the error "WARNING: An Error occurred, please let us know! If you were entering information, press the BACK button in your browser and re-check the information you had entered to be sure you entered valid data."

    Error log is below:

    [22-Sep-2023 05:28:03 UTC] Request URI: /lsadmin/index.php?cmd=category_product_listing&action=copy_product_confirm&cPath=170&pag e=1, IP address: 118.209.124.147, Language id 1
    #1 trigger_error() called at [/includes/classes/db/mysql/query_factory.php:667]
    #2 queryFactory->show_error() called at [/includes/classes/db/mysql/query_factory.php:634]
    #3 queryFactory->set_error() called at [/includes/classes/db/mysql/query_factory.php:275]
    #4 queryFactory->Execute() called at [/includes/functions/database.php:130]
    #5 zen_db_perform() called at [/lsadmin/includes/modules/copy_product_confirm.php:109]
    #6 require(/lsadmin/includes/modules/copy_product_confirm.php) called at [/lsadmin/category_product_listing.php:253]
    #7 require(/lsadmin/category_product_listing.php) called at [/lsadmin/index.php:11]
    --> PHP Fatal error: 1366:Incorrect double value: '' for column `ledsales_zc_158`.`6d6_products`.`products_length` at row 1 :: INSERT INTO 6d6_products (products_type, products_quantity, products_model, products_image, products_price, products_virtual, products_weight, products_length, products_height, products_width, dangerous_goods, products_tax_class_id, manufacturers_id, products_ordered, products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute, product_is_free, product_is_call, products_quantity_mixed, product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order, products_discount_type, products_discount_type_from, products_price_sorter, master_categories_id, products_mixed_discount_quantity, metatags_title_status, metatags_products_name_status, metatags_model_status, metatags_price_status, metatags_title_tagline_status, products_status, products_date_added, products_date_available) VALUES ('1', '4593', 'NICHIA_FLAT', 'nichia_flat.jpg', '0.2', '0', '0.5', '', '', '', '0', '0', '0', '3970', '1', '1', '0', '0', '0', '0', '0', '1', '0', '-1', '2', '0', '0.2000', '170', '0', '0', '0', '0', '0', '0', '0', now(), null) ==> (as called by) /includes/functions/database.php on line 130 <== in /includes/classes/db/mysql/query_factory.php on line 667.

    I have no idea what it means by an incorrect double value, anyone seen this before?

  2. #2
    Join Date
    Jul 2016
    Posts
    59
    Plugin Contributions
    0

    Default Re: Error on duplicating product

    Further to this, I note that trying to duplicate a product in another category worked fine, in fact I made several duplicates since I installed the new version, and tried a duplicate elsewhere today and it was fine, so it seems to just be something with this product or category. Not sure why, there's nothing special about it.

  3. #3
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,364
    Plugin Contributions
    94

    Default Re: Error on duplicating product

    Quote Originally Posted by Lance Turner View Post
    Just set up a new version of my shop (ledsales.com.au) using 1.5.8a and has been working quite well. However, today I tried to duplicate a product, which also has qty discounts and links into other categories, and got the error "WARNING: An Error occurred, please let us know! If you were entering information, press the BACK button in your browser and re-check the information you had entered to be sure you entered valid data."

    Error log is below:

    [22-Sep-2023 05:28:03 UTC] Request URI: /lsadmin/index.php?cmd=category_product_listing&action=copy_product_confirm&cPath=170&pag e=1, IP address: 118.209.124.147, Language id 1
    #1 trigger_error() called at [/includes/classes/db/mysql/query_factory.php:667]
    #2 queryFactory->show_error() called at [/includes/classes/db/mysql/query_factory.php:634]
    #3 queryFactory->set_error() called at [/includes/classes/db/mysql/query_factory.php:275]
    #4 queryFactory->Execute() called at [/includes/functions/database.php:130]
    #5 zen_db_perform() called at [/lsadmin/includes/modules/copy_product_confirm.php:109]
    #6 require(/lsadmin/includes/modules/copy_product_confirm.php) called at [/lsadmin/category_product_listing.php:253]
    #7 require(/lsadmin/category_product_listing.php) called at [/lsadmin/index.php:11]
    --> PHP Fatal error: 1366:Incorrect double value: '' for column `ledsales_zc_158`.`6d6_products`.`products_length` at row 1 :: INSERT INTO 6d6_products (products_type, products_quantity, products_model, products_image, products_price, products_virtual, products_weight, products_length, products_height, products_width, dangerous_goods, products_tax_class_id, manufacturers_id, products_ordered, products_quantity_order_min, products_quantity_order_units, products_priced_by_attribute, product_is_free, product_is_call, products_quantity_mixed, product_is_always_free_shipping, products_qty_box_status, products_quantity_order_max, products_sort_order, products_discount_type, products_discount_type_from, products_price_sorter, master_categories_id, products_mixed_discount_quantity, metatags_title_status, metatags_products_name_status, metatags_model_status, metatags_price_status, metatags_title_tagline_status, products_status, products_date_added, products_date_available) VALUES ('1', '4593', 'NICHIA_FLAT', 'nichia_flat.jpg', '0.2', '0', '0.5', '', '', '', '0', '0', '0', '3970', '1', '1', '0', '0', '0', '0', '0', '1', '0', '-1', '2', '0', '0.2000', '170', '0', '0', '0', '0', '0', '0', '0', now(), null) ==> (as called by) /includes/functions/database.php on line 130 <== in /includes/classes/db/mysql/query_factory.php on line 667.

    I have no idea what it means by an incorrect double value, anyone seen this before?
    You've got some additional fields being inserted into the products table record, and while products_length is defined as a double-type, the code is trying to set that field (as well as products_height and products_width) to an empty string. Check on/around line 109 of the file highlighted above or see if there is an observer-class file providng those updates.

  4. #4
    Join Date
    Jul 2016
    Posts
    59
    Plugin Contributions
    0

    Default Re: Error on duplicating product

    Thanks, line 108 onwards in that file is below, but I'm not a coder so have no idea if there's something in there causing the issue. It's odd that some products can be duplicated without issue while others cause the error. I created a new product in that category and I couldn't duplicate it but there is no problem creating them.

    // store new record
    zen_db_perform(TABLE_PRODUCTS, $sql_data_array);

    $dup_products_id = (int)$db->insert_ID();

    $descriptions = $db->Execute("SELECT language_id, products_name, products_description, products_url
    FROM " . TABLE_PRODUCTS_DESCRIPTION . "
    WHERE products_id = " . $products_id);
    foreach ($descriptions as $description) {
    $name = TEXT_DUPLICATE_IDENTIFIER . " " . $description['products_name'];
    $maxlen = zen_field_length(TABLE_PRODUCTS_DESCRIPTION, 'products_name');
    if (strlen($name) > $maxlen) {
    $name = substr($name, 0, $maxlen-1);
    }
    $sql_data_array = [
    'products_id' => $dup_products_id,
    'language_id' => (int)$description['language_id'],
    'products_name' => $name,
    'products_description' => $description['products_description'],
    'products_url' => $description['products_url'],
    ];
    zen_db_perform(TABLE_PRODUCTS_DESCRIPTION, $sql_data_array);
    }

    zen_link_product_to_category($dup_products_id, $categories_id);

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,364
    Plugin Contributions
    94

    Default Re: Error on duplicating product

    Grab the section above line 108 which is creating the $sql_data_array for the products table update, that's where the issue is.

  6. #6
    Join Date
    Jul 2016
    Posts
    59
    Plugin Contributions
    0

    Default Re: Error on duplicating product

    Ok, all code before that is below.

    You mentioned there are extra fields in that table, the product sizing fields, I assumed they were a normal part of the ZC products table? If not, I think I know what is going on, I was using the Aupost shipping plugin, and that has a parcel size field, but in its calcs when you turn on debugging, it was using that data as a product size, not a parcel size, so it may have added those fields when first set up?

    I was using it until last week when I turned it off, so maybe it was filling those fields in the table with data, and now with it off, that isn't happening? Just a guess, but seems an odd coincidence. The thread, starting at the relevant post, is at https://www.zen-cart.com/showthread....02#post1396802


    Code:
    if (!defined('IS_ADMIN_FLAG')) {
        die('Illegal Access');
    }
    if (isset($_POST['products_id'], $_POST['categories_id'])) {
        $products_id = (int)$_POST['products_id'];
        $categories_id = (int)$_POST['categories_id'];
    
        if ($_POST['copy_as'] === 'link') {
            if ($categories_id != $current_category_id) {
                zen_link_product_to_category($products_id, $categories_id);
                zen_record_admin_activity('Product ' . $products_id . ' copied as link to category ' . $categories_id . ' via admin console.', 'info');
            } else {
                $messageStack->add_session(ERROR_CANNOT_LINK_TO_SAME_CATEGORY, 'error');
            }
        } elseif ($_POST['copy_as'] === 'duplicate') {
    
            $product = zen_get_product_details($products_id);
    
            // fix Product copy from if Unit is 0
            if ($product->fields['products_quantity_order_units'] == 0) {
                $sql = "UPDATE " . TABLE_PRODUCTS . "
                        SET products_quantity_order_units = 1
                        WHERE products_id = " . $products_id;
                $results = $db->Execute($sql);
                $product->fields['products_quantity_order_units'] = 1;
            }
            // fix Product copy from if Minimum is 0
            if ($product->fields['products_quantity_order_min'] == 0) {
                $sql = "UPDATE " . TABLE_PRODUCTS . "
                        SET products_quantity_order_min = 1
                        WHERE products_id = " . $products_id;
                $results = $db->Execute($sql);
                $product->fields['products_quantity_order_min'] = 1;
            }
    
            $sql_data_array = [];
            $separately_updated_fields = [
              'products_id',
              'products_status',
              'products_last_modified',
              'products_date_added',
              'products_date_available',
            ];
            $casted_fields = [
              'products_quantity' =>  'float',
              'products_price' =>  'float',
              'products_weight' =>  'float',
              'products_tax_class_id' =>  'int',
              'manufacturers_id' =>  'int',
              'product_is_free' =>  'int',
              'product_is_call' =>  'int',
              'products_quantity_mixed' =>  'int',
            ];
    
            // -----
            // Give an observer the chance to add any customized fields to the two arrays above.
            //
            $zco_notifier->notify('NOTIFY_MODULES_COPY_PRODUCT_CONFIRM_DUPLICATE_FIELDS', $product, $separately_updated_fields, $casted_fields);
    
            foreach ($product->fields as $key => $value) {
                if (in_array($key, $separately_updated_fields)) {
                    continue;
                }
    
                $value = zen_db_input($value);
                if (array_key_exists($key, $casted_fields)) {
                    if ($casted_fields[$key] === 'int') {
                        $sql_data_array[$key] = (int)$value;
                    } elseif ($casted_fields[$key] === 'float') {
                        $sql_data_array[$key] = (float)$value;
                    } else {
                        $sql_data_array[$key] = (!zen_not_null($value) || $value == '' || $value == 0) ? 0 : $value;
                    }
                } else {
                    $sql_data_array[$key] = $value;
                }
            }
    
            // separately_updated_fields - last_modified and products_id are skipped
            $sql_data_array['products_status'] = 0;
            $sql_data_array['products_date_added'] = 'now()';
            $sql_data_array['products_date_available'] = (!empty($product->fields['products_date_available']) ? zen_db_input($product->fields['products_date_available']) : 'null');
    
            $sql_data_array['master_categories_id'] = $categories_id;
    
            // skip fields that belong to TABLE_PRODUCTS_DESCRIPTION and TABLE_PRODUCT_TYPES
            $fields_to_skip = [
                'language_id',
                'products_name',
                'products_description',
                'products_url',
                'products_viewed', // old, but must be excluded if present
                'allow_add_to_cart',
                'type_handler',
            ];
            foreach ($fields_to_skip as $field) {
                unset($sql_data_array[$field]);
            }

  7. #7
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,364
    Plugin Contributions
    94

    Default Re: Error on duplicating product

    Those are not standard Zen Cart fields and that error is quite weird since the data was pulled from the database to do that copy ... the invalid data has to come from somewhere!

    Anyhow, create the file /admin/includes/classes/observers/auto.fix_dimensions.php (where /admin is the name of your admin sub-directory) that contains
    PHP Code:
    <?php
    class zcObserverFixDimensions extends base
    {
        public function 
    __construct
        
    {
            
    $this->attach(
                
    $this
                [
                    
    'NOTIFY_MODULES_COPY_PRODUCT_CONFIRM_DUPLICATE_FIELDS',
                ]
            );
        }

        public function 
    updateNotifyModulesCopyProductConfirmDuplicateFields(&$class$eventID$product, &$separately_updated_fields, &$casted_fields)
        {
            
    $casted_fields array_merge($casted_fields, [
                
    'products_length' => 'float',
                
    'products_height' => 'float',
                
    'products_width' => 'float',
            ]);
        }
    }
    That will coerce those naughty fields into the float/double format that the database is looking for.

  8. #8
    Join Date
    Jul 2016
    Posts
    59
    Plugin Contributions
    0

    Default Re: Error on duplicating product

    Thanks, did that and it caused a 500 error in admin.

    Am wondering if I can just drop those fields from the product table in the database, they are mostly null anyway, and the few products with anything in there are all set to zero in those fields.

  9. #9
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,364
    Plugin Contributions
    94

    Default Re: Error on duplicating product

    What was the error logged? Certainly, you can just drop those fields if they're not in use.

  10. #10
    Join Date
    Jul 2016
    Posts
    59
    Plugin Contributions
    0

    Default Re: Error on duplicating product

    Code:
    [23-Sep-2023 00:19:32 UTC] PHP Parse error: syntax error, unexpected '{', expecting '(' in /newadmin/includes/classes/observers/auto.fix_dimensions.php on line 5
    
    [23-Sep-2023 00:19:32 UTC] Request URI: /newadmin/index.php?cmd=category_product_listing, IP address: 203.217.48.219
    --> PHP Parse error: syntax error, unexpected '{', expecting '(' in /newadmin/includes/classes/observers/auto.fix_dimensions.php on line 5.

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. Replies: 2
    Last Post: 3 Jun 2021, 09:19 PM
  2. Duplicating attributes to SAME product?
    By glamourdolleyes in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 30 Mar 2014, 05:53 PM
  3. Having trouble duplicating a script error.
    By atl2rva in forum General Questions
    Replies: 3
    Last Post: 2 Feb 2012, 05:58 PM
  4. Duplicating products AND product fields
    By manmonkey in forum Basic Configuration
    Replies: 1
    Last Post: 14 May 2009, 08:08 PM
  5. Replies: 5
    Last Post: 29 Oct 2006, 09:35 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
disjunctive-egg
Zen-Cart, Internet Selling Services, Klamath Falls, OR