Results 1 to 7 of 7
  1. #1
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    60
    Plugin Contributions
    0

    Default Help with adding attributes to many products

    We have over 6,000 products, and most of those I need to add an attribute and 3 values to. The products are in all different categories, and the match by existing attribute(from the global changes in option name manager or values manager) can't match on text attributes.
    Seems I am stuck in using phpmyadmin to try and sort out which products I need to add the attribute for. My sql is a little weak, so I was hoping a sql guru could point me in the right direction.


    Thanks Matt

  2. #2
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Help with adding attributes to many products

    You've told us some of the things that you can't match against. But to assess the feasibility of doing this with SQL, we would need to know what it is possible to match against!
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  3. #3
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    60
    Plugin Contributions
    0

    Default Re: Help with adding attributes to many products

    Sorry! I should have thought about it.


    We can match against product name having 'badge' or the attribute 'name' and 'fastener'
    I can see the products_options_id for name (a text attribute) being 1
    and fastener at 3. I can't match on just fastener it would match some products that I don't want.


    Thanks again for the reply.

  4. #4
    Join Date
    Apr 2006
    Location
    London, UK
    Posts
    10,569
    Plugin Contributions
    25

    Default Re: Help with adding attributes to many products

    That appears to be enough to select the products needing stock to be set. Do you have an algorithm for knowing how much stock to set for each product/attributes combination?
    Kuroi Web Design and Development | Twitter

    (Questions answered in the forum only - so that any forum member can benefit - not by personal message)

  5. #5
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    60
    Plugin Contributions
    0

    Default Re: Help with adding attributes to many products

    Thank you again for the prompt reply, but I think I may still need to clarify what I wanted to do. My apologies if you knew this and I am the one confused.

    We have products with the text attribute 'Name' and then a dropdown of 'Fastener' (with varying values in it). To these products we want to add a new attribute 'Please Select your Case' (and then all the options values that go with it, but the built in zen global controls can handle that, I think.)

    We don't use ZenCart for any stock functions, so they would all be left at zero.

    So, I think what I need to do is figure out how to combine these two queries on the products_attributes table:

    Code:
    SELECT *
    FROM `zen_products_attributes`
    WHERE `options_id` =1
    And

    Code:
    SELECT *
    FROM `zen_products_attributes`
    WHERE `options_id` =3
    And then add in my attribute options_id 122 (and values)
    I also think I need to only do this once per product_id


    Thanks again for helping I really do appreciate it.

  6. #6
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    60
    Plugin Contributions
    0

    Default Re: Help with adding attributes to many products

    After playing around, and learning sub-queries I made some progress. Here is what I used to get my list of product Id's that will need to have rows inserted to the zen_products_attributes table.
    Code:
    SELECT DISTINCT `products_id`
    FROM `zen_products_attributes` 
    WHERE `products_id` IN 
    (SELECT `products_id`
    FROM `zen_products_attributes`
    WHERE `options_id` = 1)
    AND `products_id` IN
    (SELECT `products_id`
    FROM `zen_products_attributes`
    WHERE `options_id` = 3)
    This returns all the products with both a name and a fastener attribute, and only once per product Id.

    I just need to learn how to wrap that query with my insert so that I can insert my values. Or I might do just one, and use the global ZC copy all options values to option name.

    Almost there! Does anyone have any ides, or smart remarks about this issue?

  7. #7
    Join Date
    Jun 2008
    Location
    Oregon
    Posts
    60
    Plugin Contributions
    0

    Default Re: Help with adding attributes to many products

    I did finally get this done, in a semi automated way.
    Code:
    SELECT DISTINCT `products_id`
    FROM `zen_products_attributes` 
    WHERE `products_id` IN 
    (SELECT `products_id`
    FROM `zen_products_attributes`
    WHERE `options_id` = 93)
    where the id is the name of the text attribute I wanted to match to.

    This returns a list of product ids, so I ran this in a php loop. Here is my code...use your own password.
    PHP Code:
    //EDIT YOUR MySQL Connection Info:
    $DB_Server =         //your MySQL Server 
    $DB_Username =                  //your MySQL User Name 
    $DB_Password =                 //your MySQL Password 
    $DB_DBName =                 //your MySQL Database Name 

    $sql "SELECT DISTINCT `products_id`
    FROM `zen_products_attributes` 
    WHERE `products_id` IN 
    (SELECT `products_id`
    FROM `zen_products_attributes`
    WHERE `options_id` = 93)

    "
    ;
    $Connect = @mysql_connect($DB_Server$DB_Username$DB_Password)
        or die(
    "Couldn't connect to MySQL:<br>" mysql_error() . "<br>" mysql_errno());

    $Db = @mysql_select_db($DB_DBName$Connect)
        or die(
    "Couldn't select database:<br>" mysql_error(). "<br>" mysql_errno());

    $result = @mysql_query($sql)
        or die(
    "Couldn't execute query:<br>" mysql_error(). "<br>" mysql_errno());
        for(
    $ik=0;$ik<mysql_num_rows($result);$ik++)  
                {
                    
    $rows mysql_fetch_assoc($result);
                    
    $sql2 "INSERT INTO `zen_products_attributes` (`products_attributes_id`, `products_id`, `options_id`, `options_values_id`, `options_values_price`, `price_prefix`, `products_options_sort_order`, `product_attribute_is_free`, `products_attributes_weight`, `products_attributes_weight_prefix`, `attributes_display_only`, `attributes_default`, `attributes_discounted`, `attributes_image`, `attributes_price_base_included`, `attributes_price_onetime`, `attributes_price_factor`, `attributes_price_factor_offset`, `attributes_price_factor_onetime`, `attributes_price_factor_onetime_offset`, `attributes_qty_prices`, `attributes_qty_prices_onetime`, `attributes_price_words`, `attributes_price_words_free`, `attributes_price_letters`, `attributes_price_letters_free`, `attributes_required`, `products_attributes_products_id`, `products_attributes_products_quantity`, `products_attributes_type`) VALUES
    (NULL," 
    $rows['products_id'] . ", 122, 322, '0.0000', '+', 0, 1, 0, '+', 1, 1, 1, '', 1, '0.0000', '0.0000', '0.0000', '0.0000', '0.0000', '', '', '0.0000', 0, '0.0000', 0, 0, 0, 0, 0), 
    (NULL," 
    $rows['products_id'] . ", 122, 320, '0.0000', '+', 0, 1, 0, '+', 0, 0, 1, '', 1, '0.0000', '0.0000', '0.0000', '0.0000', '0.0000', '', '', '0.0000', 0, '0.0000', 0, 0, 0, 0, 0), 
    (NULL," 
    $rows['products_id'] . ", 122, 321, '0.0000', '+', 0, 1, 0, '+', 0, 0, 1, '', 1, '0.0000', '0.0000', '0.0000', '0.0000', '0.0000', '', '', '0.0000', 0, '0.0000', 0, 0, 0, 0, 0) ";                            
    $Connect = @mysql_connect($DB_Server$DB_Username$DB_Password)
        or die(
    "Couldn't connect to MySQL:<br>" mysql_error() . "<br>" mysql_errno());

    $Db = @mysql_select_db($DB_DBName$Connect)
        or die(
    "Couldn't select database:<br>" mysql_error(). "<br>" mysql_errno());

    $result2 = @mysql_query($sql2)
    or die(
    "Couldn't execute query:<br>" mysql_error(). "<br>" mysql_errno());            
                }
    //for 
    Anyway, job got done, but I ended up with duplicate option values for all of them. I used the built in functions to remove and add values never removing all of them or adding all of them.

    Thanks for the help kuroi.

 

 

Similar Threads

  1. v139h adding attributes to all products with sql query
    By delia in forum General Questions
    Replies: 8
    Last Post: 22 Apr 2014, 07:40 PM
  2. v139h Adding products with multiple attributes shopping cart
    By TAIHCM in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 22 Feb 2012, 08:20 PM
  3. Replies: 0
    Last Post: 26 Jan 2012, 02:39 PM
  4. Adding many products at once
    By TRGames in forum Setting Up Categories, Products, Attributes
    Replies: 3
    Last Post: 31 Aug 2009, 09:23 PM
  5. Product with Many Attributes
    By norcalmotocross in forum Setting Up Categories, Products, Attributes
    Replies: 0
    Last Post: 17 Apr 2008, 10:37 PM

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