Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Need way to tell if shopping cart is empty from inside


Guest

Recommended Posts

Hi Guys an Gals,

 

I'm wanting to add a couple of buttons to inside the products box of the shooping cart, more specifically to have a Remove button under the remove check boxes and an update button under the qty boxes if the shopping cart is not empty.

 

Was tracking through the code and I cant see where to add the code in /shopping_cart.php in to $info_box_contents[]

 

and in the call to new productListingBox($info_box_contents); which calls tablebox, I cant call cart_contents() from the tablebox constructor.

 

Can someone help as I'm at a bit of a loss to do something that should be relativley simple to do:

add a rmove button under the remove check box and an update button under the qty box if there are products in the shopping cart.

 

This is the line of code I was trying to add in the correct place but was then having problems if the shopping cart was empty:

$tableBox_string .='<tr><td align=center>' . tep_image_submit('button_remove_cart.gif', IMAGE_BUTTON_REMOVE_CART) .	'</td><td></td><td align=center>' .  tep_image_submit('button_update_cart.gif', IMAGE_BUTTON_UPDATE_CART) . '</td><td></td></tr>';

Link to comment
Share on other sites

you are on the right track, but you need to put that code in the place where the cart contents are generated.

 

what I did was just add an other column to the shopping cart that displayed an update cart button. (made the button rather big so people would HAVE to see it. (some people don't get it when it says update, that they are supossed to click that when they want to update their carts, a floppy at the end of the line did help them notice how to update their carts.))

 

my alterations:

after:

	$info_box_contents[0][] = array('align' => 'right',

								'params' => 'class="productListing-heading"',

								'text' => TABLE_HEADING_TOTAL);

add:

	$info_box_contents[0][] = array('align' => 'right',

								'params' => 'class="productListing-heading"',

								'text' => CHANGE);

and after

 $info_box_contents[$cur_row][] = array('align' => 'right',

										 'params' => 'class="productListing-data" valign="top"',

										 'text' => '<b>' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . '</b>');

I inserted:

	  $info_box_contents[$cur_row][] = array('align' => 'right',

										 'params' => 'class="productListing-data" valign="top"',

										 'text' => tep_image_submit('floppy.gif', IMAGE_BUTTON_UPDATE_CART));

 

when you want to change the delete checkbox, change:

	  $info_box_contents[$cur_row][] = array('align' => 'center',

										 'params' => 'class="productListing-data" valign="top"',

										 'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));

you will just have to midify the

tep_draw_checkbox_field('cart_delete[]', $products[$i]['id'])

part to whatever you want it to be

Link to comment
Share on other sites

you are on the right track, but you need to put that code in the place where the cart contents are generated.

 

 

Thanks for the encouragement Jonathan.

 

Well I persevered and a few days later I have got it working the way I want it to, If you go here and "Buy Now"

http://test.newlifehealthcare.co.uk/family-c-50.html

 

This is what I changed the code to in catalog/shopping_cart.php from around line 122 to 197 (on my one)

						for ($i=0, $n=sizeof($products); $i<$n; $i++) 
					{
						if (($i/2) == floor($i/2)) 
						{
							$info_box_contents[] = array('params' => 'class="productListing-even"');
						} 
						else 
						{
							$info_box_contents[] = array('params' => 'class="productListing-odd"');
						}

						$cur_row = sizeof($info_box_contents) - 1;


						//Add Update button under the last qty box
						if(($i + 1) == $n)
						{
							$info_box_contents[$cur_row][] = array('align' => 'center',
							'params' => 'class="productListing-data" valign="top"',
							'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']) ."<br><br>" . tep_image_submit('button_remove_cart.gif', IMAGE_BUTTON_REMOVE_CART));
						}
						else
						{
							$info_box_contents[$cur_row][] = array('align' => 'center',
							'params' => 'class="productListing-data" valign="top"',
							'text' => tep_draw_checkbox_field('cart_delete[]', $products[$i]['id']));
						}


						//Remove the need for wrapping in a seperate table
						$products_name = '<a href="' . tep_href_link(FILENAME_PRODUCT_INFO, 'products_id=' . $products[$i]['id']) . '"><b>' . $products[$i]['name'] . '</b></a>';

						if (STOCK_CHECK == 'true') 
						{
							$stock_check = tep_check_stock($products[$i]['id'], $products[$i]['quantity']);
							if (tep_not_null($stock_check)) 
							{
								$any_out_of_stock = 1;

								$products_name .= $stock_check;
							}
						}

						if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) 
						{
							reset($products[$i]['attributes']);
							while (list($option, $value) = each($products[$i]['attributes'])) 
							{
								$products_name .= '<br><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
							}
						}

						// Make sure the product is aligned to the top of the cell not to be affected by adding in the Remove button
						$info_box_contents[$cur_row][] = array('params' => 'class="productListing-data" valign="baseline"',
						'text' => $products_name);

						//Add Update button under the last qty box
						if(($i + 1) == $n)
						{
							$info_box_contents[$cur_row][] = array('align' => 'center',
							'params' => 'class="productListing-data" valign="top"',
							'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') ."<br><br>" . tep_image_submit('button_update_cart.gif', IMAGE_BUTTON_UPDATE_CART) . tep_draw_hidden_field('products_id[]', $products[$i]['id']));
						}
						else
						{
							$info_box_contents[$cur_row][] = array('align' => 'center',
							'params' => 'class="productListing-data" valign="top"',
							'text' => tep_draw_input_field('cart_quantity[]', $products[$i]['quantity'], 'size="4"') . tep_draw_hidden_field('products_id[]', $products[$i]['id']));
						}

						$info_box_contents[$cur_row][] = array('align' => 'right',
						'params' => 'class="productListing-data" valign="top"',
						'text' => '<b>' . $currencies->display_price($products[$i]['final_price'], tep_get_tax_rate($products[$i]['tax_class_id']), $products[$i]['quantity']) . '</b>');
					}

					new productListingBox($info_box_contents);

 

Thanks,

Ally

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...