Zen Cart Logo
Forums / General Questions / Which file contains the code for "Add to cart"?

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

Views: 1,223

Results 1 to 12 of 12
6 Oct 2015, 3:16 PM
#1
joecooper avatar

joecooper

Zen Follower

Join Date:
Aug 2011
Posts:
122
Plugin Contributions:
0

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.

6 Oct 2015, 3:33 PM
#2
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,099
Plugin Contributions:
56

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.

6 Oct 2015, 3:39 PM
#3
joecooper avatar

joecooper

Zen Follower

Join Date:
Aug 2011
Posts:
122
Plugin Contributions:
0

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?

6 Oct 2015, 4:07 PM
#4
joecooper avatar

joecooper

Zen Follower

Join Date:
Aug 2011
Posts:
122
Plugin Contributions:
0

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.

<?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

6 Oct 2015, 4:21 PM
#5
lat9 avatar

lat9

Administrator

Join Date:
Sep 2009
Location:
Stuart, FL
Posts:
14,099
Plugin Contributions:
56

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:

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 Oct 2015, 4:26 PM
#6
joecooper avatar

joecooper

Zen Follower

Join Date:
Aug 2011
Posts:
122
Plugin Contributions:
0

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.

6 Oct 2015, 7:58 PM
#7
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

joecooper:

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.

7 Oct 2015, 10:27 AM
#8
joecooper avatar

joecooper

Zen Follower

Join Date:
Aug 2011
Posts:
122
Plugin Contributions:
0

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/32989687/how-to-unset-a-key-on-a-post-array?noredirect=1#comment53803987_32989687

but got a negative response about doing it.

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

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]']);	
	}

}
7 Oct 2015, 10:46 AM
#9
joecooper avatar

joecooper

Zen Follower

Join Date:
Aug 2011
Posts:
122
Plugin Contributions:
0

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

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

<?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]);	
	}

}


?>
7 Oct 2015, 11:09 AM
#10
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

joecooper:

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

<?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...
7 Oct 2015, 3:01 PM
#11
joecooper avatar

joecooper

Zen Follower

Join Date:
Aug 2011
Posts:
122
Plugin Contributions:
0

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

I have modified that particular attribute to be a hidden field, which is controlled by JQuery and Javascript, depending on which type of monogram has been selected.

Since Zen Cart doesn't support sub attributes, I have had to build it this way, otherwise the cart would display both a style and a font which got confusing for the client and customers.

I have added an option on every product page to click a button which then displays a monogramming options page with an API for displaying the monogram.

Here is what it looks like at the moment, and works quite well.
Attachment 15676

7 Oct 2015, 4:07 PM
#12
mc12345678 avatar

mc12345678

Totally Zenned

Join Date:
Jul 2012
Posts:
16,908
Plugin Contributions:
2

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

Well, multiple ways to accomplish the same task, but looks like because the text of the text box is "auto-assigned" that the concern expressed above is not a direct issue.