Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2011
    Posts
    103
    Plugin Contributions
    0

    bug [Done v155c] $product_type incorrectly set in admin/product.php

    Using 1.5.5a. Pretty sure this bug has been around since 1.5.4, since I located it in a pre-upgrade file, too. I didn't see any obvious references to this, nor addressed in 1.5.5b changelogs, so hopefully it's not a repeat.

    This bug only becomes evident when expanding product types. The only place $product_type is defined is within the case of "delete_product_confirm" action. I have several custom product types with custom delete_product_confirm and copy_to_confirm files. I couldn't figure out why it kept using the default copy_to file and thus not correctly copying my extra tables, but then after far-too-long, I realized that $product_type wasn't defined for the copy_to_confirm action.

    product.php code:
    Beginning Ln19:

    PHP Code:
      if (zen_not_null($action)) {
        switch (
    $action) {
          case 
    'setflag':
            if ( (
    $_GET['flag'] == '0') || ($_GET['flag'] == '1') ) {
              if (isset(
    $_GET['pID'])) {
                
    zen_set_product_status($_GET['pID'], $_GET['flag']);
              }
            }
            
    zen_redirect(zen_href_link(FILENAME_CATEGORIES'cPath=' $_GET['cPath'] . '&pID=' $_GET['pID'] . (isset($_GET['page']) ? '&page=' $_GET['page'] : '') . ((isset($_GET['search']) && !empty($_GET['search'])) ? '&search=' $_GET['search'] : '')));
            break;

          case 
    'delete_product_confirm':
          
    $delete_linked 'true';
          if (
    $_POST['delete_linked'] == 'delete_linked_no') {
            
    $delete_linked 'false';
          } else {
            
    $delete_linked 'true';
          }
          
    $product_type zen_get_products_type($_POST['products_id']);
            if (
    file_exists(DIR_WS_MODULES $zc_products->get_handler($product_type) . '/delete_product_confirm.php')) {
              require(
    DIR_WS_MODULES $zc_products->get_handler($product_type) . '/delete_product_confirm.php');
             } else {
              require(
    DIR_WS_MODULES 'delete_product_confirm.php');
             }
            break;
          case 
    'move_product_confirm':
            if (
    file_exists(DIR_WS_MODULES $zc_products->get_handler($product_type) . '/move_product_confirm.php')) {
              require(
    DIR_WS_MODULES $zc_products->get_handler($product_type) . '/move_product_confirm.php');
             } else {
              require(
    DIR_WS_MODULES 'move_product_confirm.php');
             }
            break; 
    I resolved the bug by moving the $product_type definition to right after the
    PHP Code:
    if (zen_not_null($action)) { 
    and changing it to....

    PHP Code:
    $product_type = (isset($_POST['products_id']) ? zen_get_products_type($_POST['products_id']) : $_GET['product_type']); 
    Result:
    PHP Code:
      if (zen_not_null($action)) {

        
    $product_type = (isset($_POST['products_id']) ? zen_get_products_type($_POST['products_id']) : $_GET['product_type']); // Changed

        
    switch ($action) {
          case 
    'setflag':
            if ( (
    $_GET['flag'] == '0') || ($_GET['flag'] == '1') ) {
              if (isset(
    $_GET['pID'])) {
                
    zen_set_product_status($_GET['pID'], $_GET['flag']);
              }
            }
            
    zen_redirect(zen_href_link(FILENAME_CATEGORIES'cPath=' $_GET['cPath'] . '&pID=' $_GET['pID'] . (isset($_GET['page']) ? '&page=' $_GET['page'] : '') . ((isset($_GET['search']) && !empty($_GET['search'])) ? '&search=' $_GET['search'] : '')));
            break;

          case 
    'delete_product_confirm'
    Not 100% if that's the best redefinition of the code, but it works in the instances I need it to. Mostly, $_GET['product_type'] seems to cover most instances. This will apply to all the product_HANDLER.php pages, afaik.

  2. #2
    Join Date
    Jan 2004
    Posts
    66,373
    Blog Entries
    7
    Plugin Contributions
    274

    Default Re: $product_type incorrectly set in admin/product.php

    Thanks for the detective work and the proposed solution.

    While digging further, and with a view to helping resolve it for all product types, I opted to move that line out of the products.php file, into the prod-cat-header.php file, as shown here:
    https://github.com/zencart/zencart/pull/1352/files
    .

    Zen Cart - putting the dream of business ownership within reach of anyone!
    Donate to: DrByte directly or to the Zen Cart team as a whole

    Remember: Any code suggestions you see here are merely suggestions. You assume full responsibility for your use of any such suggestions, including any impact ANY alterations you make to your site may have on your PCI compliance.
    Furthermore, any advice you see here about PCI matters is merely an opinion, and should not be relied upon as "official". Official PCI information should be obtained from the PCI Security Council directly or from one of their authorized Assessors.

 

 

Similar Threads

  1. Replies: 0
    Last Post: 25 Dec 2014, 04:57 PM
  2. Replies: 5
    Last Post: 16 Jan 2009, 10:05 AM
  3. Custom product_type and products_options_types in tpl_shopping_cart_default.php
    By Besjon in forum Setting Up Categories, Products, Attributes
    Replies: 1
    Last Post: 18 Nov 2007, 08:36 PM
  4. Replies: 1
    Last Post: 2 Nov 2006, 11:02 PM
  5. Replies: 3
    Last Post: 11 Aug 2006, 10:54 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