Page 1 of 2 12 LastLast
Results 1 to 10 of 12
  1. #1
    Join Date
    Aug 2011
    Posts
    121
    Plugin Contributions
    0

    Default Which file contains the code for "Add to cart"?

    Just a quick one.

    I have a main attribute which chooses which sub-attribute to display via JQuery. But since both sub-attributes are drop downs, they still get submitted on their default option.

    I am struggling to find the file which processes the "Add to cart" information to ignore one or the other attribute based on the main attribute.

    Thanks.

  2. #2
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,969
    Plugin Contributions
    96

    Default Re: Which file contains the code for "Add to cart"?

    Based on your description, it sounds like you'll want to add a file to the /extra_cart_actions folder, taking "action" when $_GET['action'] is set to 'add_product'.

    You can then interrogate the $_POST['id'] array (that contains the attributes) and take action based on your attribute hierarchy, removing any extraneous attribute values.

  3. #3
    Join Date
    Aug 2011
    Posts
    121
    Plugin Contributions
    0

    Default Re: Which file contains the code for "Add to cart"?

    So this will run before any other code is ran? And I'll remove the attrubite information, then the usual "add to cart" option deals with the rest? (with attribute removed). Is this right?

  4. #4
    Join Date
    Aug 2011
    Posts
    121
    Plugin Contributions
    0

    Default Re: Which file contains the code for "Add to cart"?

    Ok, so I have tested this, but can't seem to get any data about the attributes.

    Code:
    <?php
    if (($_GET['action'] == 'add_product')) {
    echo("<table>");
     foreach ($_POST as $key => $value) {
            echo "<tr>";
            echo "<td>";
            echo $key;
            echo "</td>";
            echo "<td>";
            echo $value;
            echo "</td>";
            echo "</tr>";
        }
    	echo("</table>");
    	die("");
    	}
    ?>
    displays:

    securityToken f5b7fcaa0fa568ffc53f504d7233f123
    id Array
    cart_quantity 1
    products_id 44

  5. #5
    Join Date
    Sep 2009
    Location
    Stuart, FL
    Posts
    13,969
    Plugin Contributions
    96

    Default Re: Which file contains the code for "Add to cart"?

    What you said in post#3 is correct; this code will run before the "other" add-to-cart processing.

    The $_POST['id'] value is (as printed out) an array; you'll need to cycle through them. One hint, you can initially simply dump the contents of the $_POST variables so you can see what you're dealing with:
    Code:
    error_log (__FILE__ . ': POST variables: ' . print_r ($_POST, true));
    That will create a myDEBUG*.log file (in your /logs directory) that has the variable dump.

  6. #6
    Join Date
    Aug 2011
    Posts
    121
    Plugin Contributions
    0

    Default Re: Which file contains the code for "Add to cart"?

    Yep managed to do the same with var_dump($_POST['id']); so now I can see the values.

    I can then pull the value. but unsure how to modify the value? Although thats more PHP related and I'm sure google has the answer.

    Many thanks for your help.

  7. #7
    Join Date
    Jul 2012
    Posts
    16,817
    Plugin Contributions
    17

    Default Re: Which file contains the code for "Add to cart"?

    Quote Originally Posted by joecooper View Post
    Yep managed to do the same with var_dump($_POST['id']); so now I can see the values.

    I can then pull the value. but unsure how to modify the value? Although thats more PHP related and I'm sure google has the answer.

    Many thanks for your help.
    $_POST is itself a variable, and can be modified as such. If no further action is being taken by this sub-code, then simply referencing/modifying/deleting the applicable data will leave $_POST intact with the whatever it is set to to be processed by the standard/remaining code/processing.
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

  8. #8
    Join Date
    Aug 2011
    Posts
    121
    Plugin Contributions
    0

    Default Re: Which file contains the code for "Add to cart"?

    It seems like I'm unable to modify the variable.

    I posted the question on here: http://stackoverflow.com/questions/3...03987_32989687

    but got a negative response about doing it.

    This is the code, but it isn't able to unset the key:

    Code:
    if (($_GET['action'] == 'add_product')) {
    	if($_POST['id']['txt_10'] == "initials"){
    	
    		unset($_POST['id']['id[8]']);
    	}else if($_POST['id']['txt_10'] == "name"){
    		unset($_POST['id']['id[9]']);	
    	}
    
    }

  9. #9
    Join Date
    Aug 2011
    Posts
    121
    Plugin Contributions
    0

    Default Re: Which file contains the code for "Add to cart"?

    Glad to say it was just me being silly. This works fine:

    Code:
    <?php
    
    if (($_GET['action'] == 'add_product')) {
    	if($_POST['id']['txt_10'] == "Initials"){
    	
    		unset($_POST['id'][8]);
    	}else if($_POST['id']['txt_10'] == "Name"){
    		unset($_POST['id'][4]);	
    	}
    
    }
    
    
    ?>

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

    Default Re: Which file contains the code for "Add to cart"?

    Quote Originally Posted by joecooper View Post
    Glad to say it was just me being silly. This works fine:

    Code:
    <?php
    
    if (($_GET['action'] == 'add_product')) {
    	if($_POST['id']['txt_10'] == "Initials"){
    	
    		unset($_POST['id'][8]);
    	}else if($_POST['id']['txt_10'] == "Name"){
    		unset($_POST['id'][4]);	
    	}
    
    }
    
    
    ?>
    As far as those text block checks, is that customer entered data? If so, what additional checks are in place to ensure it is entered exactly as provided? Ie what if name is entered? Or NAME? Etc...
    ZC Installation/Maintenance Support <- Site
    Contribution for contributions welcome...

 

 
Page 1 of 2 12 LastLast

Similar Threads

  1. v151 Display "add to cart" and "Call for price together"
    By Tadj Hemingway in forum General Questions
    Replies: 2
    Last Post: 6 Mar 2015, 07:53 PM
  2. Replies: 0
    Last Post: 17 Mar 2010, 05:24 PM
  3. Which file to reupload for "I am able to write to..." error
    By jwebster in forum General Questions
    Replies: 2
    Last Post: 6 Mar 2010, 06:12 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