Page 1 of 2 12 LastLast
Results 1 to 10 of 14
  1. #1
    Join Date
    May 2014
    Location
    United States
    Posts
    5
    Plugin Contributions
    0

    Default Duplicate Model Numbers warning!

    There has been many posts about Duplicate model numbers or people who have made that field part number. anyhow below is a simple method to warn you when adding products.

    public_html/your_admin/includes/modules/new_product_preview.php

    paste code below just above ?> at the end of the page. Thats it.


    Code:
             $products_model = $_POST['products_model'];
             
     $dups_query_raw = "SELECT products_model FROM " . TABLE_PRODUCTS . " WHERE products_model = '" .$products_model. "'";
    
     $dups = $db->Execute($dups_query_raw);
        if ($dups->RecordCount() > 0) { 
    
       $trigger_error = "<span style='color: red; font-size: 14pt; background-color: #FFFF00'>Part number '" .$products_model. "' already exists '" .$dups->RecordCount(). "' times! <a href ='https://www.your-domain.com/your-admin/categories.php?search=" .$products_model. "'>Click Here</a> to add to correct one.</span>";
       
        echo $trigger_error;
    }else{
    
    
    }

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

    Default Re: Duplicate Model Numbers warning!

    Thanks for posting your suggestion.

    When looking it over I found that there are some problems with the code you posted:
    - It needs a bit of rewriting to be more secure.
    - It currently requires manual entry of the site URL in the custom code
    - Has an empty "else" clause, which can be removed

    Here's an improved way:

    Code:
    // check for duplicates
    $products_model = $_POST['products_model'];
    
    
    $dups_query_raw = "SELECT products_model FROM " . TABLE_PRODUCTS . " WHERE products_model = :model ";
    $dups_query_raw = $db->bindVars($dups_query_raw, ':model', $products_model, 'string');
    
    
    $dups = $db->Execute($dups_query_raw);
    if ($dups->RecordCount() > 0) {
      $trigger_error = '<span style="color: red; font-size: 14pt; background-color: #FFFF00">
      Product Model number ' . zen_output_string_protected($products_model) . ' already exists ' . $dups->RecordCount() . ' times!
      <a href ="' . zen_href_link(FILENAME_CATEGORIES, 'search=' . zen_output_string_protected($products_model)) . '" target="_blank">Click Here</a> to view the duplicates.</span>';
      echo $trigger_error;
    }
    It's still not multi-language friendly, so could use adjustments to handle that also.
    .

    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.

  3. #3
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Duplicate Model Numbers warning!

    May I suggest to incorporate this code in the next update of ZC (v 1.5.4 ??) - thanks.

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

    Default Re: Duplicate Model Numbers warning!

    Quote Originally Posted by frank18 View Post
    May I suggest to incorporate this code in the next update of ZC (v 1.5.4 ??) - thanks.
    While the above will work if implemented on 1.5.4 (indeed any 1.5.x), it's not ready for core code implementation.

    It's not multi-language friendly. It assumes model numbers need to be unique. It doesn't have anything that lets the storeowner be the one to decide whether they even want the feature.

    A solution for-the-masses would probably be better done with ajax in-page. Maybe for 1.6.0.
    .

    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.

  5. #5
    Join Date
    Nov 2007
    Location
    Sunny Coast, Australia
    Posts
    3,379
    Plugin Contributions
    9

    Default Re: Duplicate Model Numbers warning!

    Quote Originally Posted by DrByte View Post
    While the above will work if implemented on 1.5.4 (indeed any 1.5.x), it's not ready for core code implementation.

    It's not multi-language friendly. It assumes model numbers need to be unique. It doesn't have anything that lets the storeowner be the one to decide whether they even want the feature.

    A solution for-the-masses would probably be better done with ajax in-page. Maybe for 1.6.0.
    Makes perfect sense - thanks DrByte

  6. #6
    Join Date
    Dec 2009
    Location
    Amersfoort, The Netherlands
    Posts
    2,846
    Plugin Contributions
    25

    Default Re: Duplicate Model Numbers warning!

    Quote Originally Posted by frank18 View Post
    Makes perfect sense - thanks DrByte
    There already is a duplicate model module. This lets you check manually for duplicates.

  7. #7
    Join Date
    May 2014
    Location
    United States
    Posts
    5
    Plugin Contributions
    0

    Default Re: Duplicate Model Numbers warning!

    Had to make a change to
    if ($dups->RecordCount() > 0) {
    if ($dups->RecordCount() > 1) {


    Code:
    // check for duplicates
    $products_model = $_POST['products_model'];
    
    
    $dups_query_raw = "SELECT products_model FROM " . TABLE_PRODUCTS . " WHERE products_model = :model ";
    $dups_query_raw = $db->bindVars($dups_query_raw, ':model', $products_model, 'string');
    
    
    $dups = $db->Execute($dups_query_raw);
    if ($dups->RecordCount() > 1) {
      $trigger_error = '<span style="color: red; font-size: 14pt; background-color: #FFFF00">
      Product Model number ' . zen_output_string_protected($products_model) . ' already exists ' . $dups->RecordCount() . ' times!
      <a href ="' . zen_href_link(FILENAME_CATEGORIES, 'search=' . zen_output_string_protected($products_model)) . '" target="_blank">Click Here</a> to view the duplicates.</span>';
      echo $trigger_error;
    }

  8. #8
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Duplicate Model Numbers warning!

    Quote Originally Posted by jcurtice View Post
    Had to make a change to
    if ($dups->RecordCount() > 0) {
    if ($dups->RecordCount() > 1) {



    // check for duplicates
    $products_model = $_POST['products_model'];


    $dups_query_raw = "SELECT products_model FROM " . TABLE_PRODUCTS . " WHERE products_model = :model ";
    $dups_query_raw = $db->bindVars($dups_query_raw, ':model', $products_model, 'string');


    $dups = $db->Execute($dups_query_raw);
    if ($dups->RecordCount() > 1) {
    $trigger_error = '<span style="color: red; font-size: 14pt; background-color: #FFFF00">
    Product Model number ' . zen_output_string_protected($products_model) . ' already exists ' . $dups->RecordCount() . ' times!
    <a href ="' . zen_href_link(FILENAME_CATEGORIES, 'search=' . zen_output_string_protected($products_model)) . '" target="_blank">Click Here</a> to view the duplicates.</span>';
    echo $trigger_error;
    }
    Was the change needed to support identifying that a model # being pushed to the database already exists before pushing the new data, or was it necessary to support going through the database to see if duplicates already exist?
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  9. #9
    Join Date
    May 2014
    Location
    United States
    Posts
    5
    Plugin Contributions
    0

    Default Re: Duplicate Model Numbers warning!

    Quote Originally Posted by mc12345678 View Post
    Was the change needed to support identifying that a model # being pushed to the database already exists before pushing the new data, or was it necessary to support going through the database to see if duplicates already exist?
    The change was necessary to mine because it was looking for anything greater than 0 and when you tried to add 1 it would give you a warning. I wanted to know if there is anything greater than 1. Which means now if I already have 1 Part number/product model in stock it will warn the person entering the part. We use the product model field for the part number because zen cart does not offer a part number field. We had hundreds of duplicate part numbers in our site which was bad. I was using the find duplicate models script but workers were entering duplicates as fast as I could remove them. And adding duplicates messes up our inventory. I needed a way to stop them from being entered to start with. We also us the manufactures name for stock location because zen cart again does not offer that field. These are two simple things that should could with every shopping cart script. Things I have managed to work around because I find zen cart much more user friendly then all the rest.

  10. #10
    Join Date
    Jul 2012
    Posts
    16,734
    Plugin Contributions
    17

    Default Re: Duplicate Model Numbers warning!

    Quote Originally Posted by jcurtice View Post
    The change was necessary to mine because it was looking for anything greater than 0 and when you tried to add 1 it would give you a warning. I wanted to know if there is anything greater than 1. Which means now if I already have 1 Part number/product model in stock it will warn the person entering the part. We use the product model field for the part number because zen cart does not offer a part number field. We had hundreds of duplicate part numbers in our site which was bad. I was using the find duplicate models script but workers were entering duplicates as fast as I could remove them. And adding duplicates messes up our inventory. I needed a way to stop them from being entered to start with. We also us the manufactures name for stock location because zen cart again does not offer that field. These are two simple things that should could with every shopping cart script. Things I have managed to work around because I find zen cart much more user friendly then all the rest.
    The thing is, checking to see if the RecordCount is greater than 1 means that the item/information has already been entered into the database and now must be addressed to remove the entry. The test of the entered (typed in) model information should be performed before the assignment of the data to the database so that it never gets added and that way the "user" can be shown an error message and allowed to return/re-enter the applicable data. From looking at this little snippet as it was rewritten, it appears that any number of duplicate model numbers could exist and as each one is added again, then the user is presented with the message of seeing which is where and does not exactly prevent the entry of the duplicate data.

    As for the fields that are "missing", there are ways to add additional fields to the database or as has been chosen to use the existing fields differently. I'm sure I'm in a minority of users, but in dog rescue we don't exactly have "part numbers", so that additional field (or series of fields/array as couldn't in say the automotive business several part numbers all relate to a single product?) Isn't something we "need". I'm not saying that it shouldn't be added, but am offering a different perspective as this code is predominantly modified to support the majority although bug fixes are made for all (when they can be reproduced).

    In fact for our rescue we created a new product type to address all of the information we need to capture, some of which is used for display, some for internal data tracking, some to be manipulated based on existing information entered on the form, etc... Seemed like the cleanest way to manage the information and maintain the database as normalized as possible.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. model numbers
    By newyorksong in forum General Questions
    Replies: 5
    Last Post: 2 Jun 2011, 10:03 PM
  2. Model Numbers?
    By gizmo_girl in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 31 Oct 2008, 05:48 PM
  3. Suppressing duplicate model numbers in the product list?
    By lismith in forum Setting Up Categories, Products, Attributes
    Replies: 8
    Last Post: 8 Aug 2007, 04:46 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