Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

How to count the number of references that I just put in the shopping cart?


bonbec

Recommended Posts

Hello,

 

I am currently working locally on my new site with Osc 2.3.4BS edge.
I installed Master Products and I modified it a bit so that it fits into my product_info.php page (see screenshot).
It works perfectly: I choose the quantities of the products slaves and I click on the green button of the master product to add the whole to the basket.
The modal cart appears but displays all the contents of the cart:
- a product already in cart
- master product
- Slave 1
- slave 2

I just want it to display only the master product and the slaves products that I just put to the cart:
- master product
- Slave 1
- slave 2

The ShoppingCart Object via $ _SESSION contains all the products, so it's not good.
The ShoppingCart Object also contains a value for new_products_id_in_cart, but it is the ID of the last slave placed in the shopping cart. If I have 2 slaves as in my example, I miss an ID
I can retrieve the master product ID with $ _GET.
$ _POST does not contain anything.

Someone would have any idea ? I've been going round in circles since this morning without finding a solution.
In advance thank you for a possible way.

post-158549-0-71050500-1492087056_thumb.jpg

with OsC 2.2 since 2006 ...

Link to comment
Share on other sites

My idea is to use my tips : http://www.oscommerce.com/forums/topic/408056-bootstrap-modal-cart-with-upsell-product/page-3#entry1751784

But modufy the line : $i = count($products)-1; by $i = count($products)-XX; where XX is the number of references to show only the product master and the slaves.

with OsC 2.2 since 2006 ...

Link to comment
Share on other sites

@frankl

 

Thanks for your help.

 

The 3 ID used are :

26 = the master product

5 = slave 1

8 = slave 2

 

In my product page, i choose ID5 (slave 1) and ID8 (slave 2) and then ID26 (buy button).

 

In the modal cart :

$new_products_id_in_cart = 8
tep_session_is_registered('new_products_id_in_cart') = 1

 

ID8 is the slave 2, the last slave I add.

 

At night carrying advice, I will try to see if I can not put a counter in application_top.php, in the part
// customer adds multiple products from the master_listing page
And retrieve the value of this counter in the modal cart.

But I would have preferred to retrieve the value I need in an existing variable.

with OsC 2.2 since 2006 ...

Link to comment
Share on other sites

At night carrying advice, I will try to see if I can not put a counter in application_top.php, in the part

// customer adds multiple products from the master_listing page

And retrieve the value of this counter in the modal cart.

But I would have preferred to retrieve the value I need in an existing variable.

 

It's work with a counter in application_top.php

Just after :

//Master Products
      // customer adds multiple products from the master_listing page
      case 'add_slave' :

Add :

                              // ADD for last products in modal cart      
                              $qty_slaves = 0;
                              // END for last products in modal cart      

At the end, find :

                                }
                              }
// switch off redirect to see debug arrays								
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
//Master Products EOF

Just before, add :

								  // ADD for last products in modal cart	  
								  $qty_slaves = $qty_slaves + 1;
								  // END for last products in modal cart	  

Now, for the modal cart, in the includes/modules/content/footer/cm_footer_modal_cart.php :

Find :

    function execute() {
      global $oscTemplate, $cart, $currencies, $languages_id, $qty_slaves, $new_products_id_in_cart;

      if (tep_session_is_registered('new_products_id_in_cart') && DISPLAY_CART == 'false') {

	  $cart_contents_string = '<table class="table table-striped table-condensed">';
        if ($cart->count_contents() > 0) {
          $products = $cart->get_products();

Add just after :

// ADD for last products in modal cart	  
$qty_products = (int)count($products);
$iqs = 0;
if($qty_products > $qty_slaves){
	$iqs = $qty_slaves;
}
if($qty_slaves == 1){
	$iqs = count($products)-1;
}

//          for ($i=0, $n=sizeof($products); $i<$n; $i++) {  <== original line, modified in the next line
          for ($i=$iqs, $n=sizeof($products); $i<$n; $i++) {
// END for last products in modal cart

Find :

        ob_start();
        include('includes/modules/content/' . $this->group . '/templates/modal_cart.php');
        $template = ob_get_clean();

Just before, add :

// ADD for last products in modal cart
		$qty_slaves = 0;
// END for last products in modal cart

It's good for me. As I am not a coder, the code can probably be cleaner.

 

with OsC 2.2 since 2006 ...

Link to comment
Share on other sites

  • 3 weeks later...

In fact, there is a big bug that I had not seen in my tests: when you put the same master item several times with different slave products, the master product is not displayed.
As I can not correct my previous post, ignore my previous post.
Use only this:

 

It's work with a counter I put in a session in application_top.php.

The lines marked with // line added are to be added.

//Master Products
      // customer adds multiple products from the master_listing page
      case 'add_slave' :
				$qty_slaves = ''; // line added
							// switch off redirect to see debug arrays
							  // END for last products in modal cart	  
                              while ( list( $key, $val ) = each( $_POST ) ) {
                                if (substr($key,0,11) == "Qty_ProdId_" && ((int)$val !== 0)) {	
                                  $prodId = substr($key,11);
								  $qty_slaves .= $prodId.' '; // line added
                                  $qty = $val;
                                  if(isset($_POST["id_$prodId"]) && is_array($_POST["id_$prodId"])) {
                                    // We have attributes
                                    $cart->add_cart($prodId, $cart->get_quantity(tep_get_uprid($prodId, $_POST["id_$prodId"]))+$qty, $_POST["id_$prodId"]);
                                  } else {
                                    if (isset($_POST["products_id"]) && isset($_POST['id'])) {
                                       // We have attributes with normal product only
                                      if ($prodId == $_POST['products_id']) {
                                        $attributes = $_POST['id'];
                                      } else {
                                        $attributes = $_POST["id_$prodId"];
                                      }
                                      $cart->add_cart($prodId, $cart->get_quantity(tep_get_uprid($prodId, $attributes))+$qty, $attributes);
                                    } else {
                                    // No attributes and normal products
                                    $cart->add_cart($prodId, $cart->get_quantity($prodId)+$qty);
                                    }
                                  }
								    
                                }
								
                              }
							  $qty_slaves = trim($qty_slaves); // line added
							  tep_session_register('qty_slaves'); // line added
// switch off redirect to see debug arrays				
                              tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));
                              break;
//Master Products EOF

Now, for the modal cart, in the includes/modules/content/footer/cm_footer_modal_cart.php :

The lines marked with // line added are to be added.

The good function execute() :

    function execute() {
      global $oscTemplate, $cart, $currencies, $languages_id;

      if (tep_session_is_registered('new_products_id_in_cart') && DISPLAY_CART == 'false') {

	  $cart_contents_string = '<table class="table table-striped table-condensed">';
        if ($cart->count_contents() > 0) {
          $products = $cart->get_products();
		  
		  
if (tep_session_is_registered('qty_slaves')) { // line added
	$qty_slaves = $_SESSION['qty_slaves']; // line added
	$qs_id = explode(" ", $qty_slaves); // line added
} // line added

  for ($i=0, $n=sizeof($products); $i<$n; $i++) {

	for ($iqs=0, $nn=sizeof($qs_id); $iqs<$nn; $iqs++) { // line added

	if( $qs_id[$iqs] == (int)$products[$i]['id']){ // line added

            $cart_contents_string .= '<tr><td>';
            $cart_contents_string .= $products[$i]['quantity'] . ' x <a href="' . tep_href_link('product_info.php', 'products_id=' . $products[$i]['id']) . '">';
            $cart_contents_string .= $products[$i]['name'] . '</a>';

// Push all attributes information in an array
	  if (isset($products[$i]['attributes']) && is_array($products[$i]['attributes'])) {
		  		  
	    while (list($option, $value) = each($products[$i]['attributes'])) {

//		  echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
									   
  //BOF - Zappo - Option Types v2 - (Hidden field moved below)
		$attributes = tep_db_query("select popt.products_options_name, poval.products_options_values_name, pa.options_values_price, pa.price_prefix
									  from products_options popt, products_options_values poval, products_attributes pa
									  where pa.products_id = '" . (int)$products[$i]['id'] . "'
									   and pa.options_id = '" . (int)$option . "'
									   and pa.options_id = popt.products_options_id
									   and pa.options_values_id = '" . (int)$value . "'
									   and pa.options_values_id = poval.products_options_values_id
									   and popt.language_id = '" . (int)$languages_id . "'
									   and poval.language_id = '" . (int)$languages_id . "'");
		  $attributes_values = tep_db_fetch_array($attributes);
// - Zappo - Option Types v2 - If attrib is Text, assign to $attr_value temporarily (Here's that hidden field)
		  if ($value == (int)OPTIONS_VALUE_TEXT_ID) {
            echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . TEXT_PREFIX . $option . ']', $products[$i]['attributes_values'][$option]);
            $attr_value = $products[$i]['attributes_values'][$option];
          } else {
            echo tep_draw_hidden_field('id[' . $products[$i]['id'] . '][' . $option . ']', $value);
            $attr_value = $attributes_values['products_options_values_name'];
          }				  
//EOF - Zappo - Option Types v2 - (Line above Assigns $attr_value)
          $products[$i][$option]['products_options_name'] = $attributes_values['products_options_name'];
          $products[$i][$option]['options_values_id'] = $value;
          $products[$i][$option]['products_options_values_name'] = $attr_value; // $attributes_values['products_options_values_name'];
          $products[$i][$option]['options_values_price'] = $attributes_values['options_values_price'];
          $products[$i][$option]['price_prefix'] = $attributes_values['price_prefix'];

                $cart_contents_string .= '<br /><small><i> - ' . $products[$i][$option]['products_options_name'] . ' ' . $products[$i][$option]['products_options_values_name'] . '</i></small>';
              }
            }

            $cart_contents_string .= '</td>';
            //image
            $cart_contents_string .= '<td class="hidden-xs hidden-sm"><a href="' . tep_href_link('product_info.php', 'products_id=' . $products[$i]['id']) . '">' . tep_image('images/' . $products[$i]['image'], $products[$i]['name'], SMALL_IMAGE_WIDTH, SMALL_IMAGE_HEIGHT) . '</a></td>';

            $products_tax = tep_get_tax_rate($products[$i]['tax_class_id']);
            $popup_price = $currencies->calculate_price($products[$i]['final_price'], $products_tax, $products[$i]['quantity']);
            $cart_contents_string .= '<td style="text-align: right; padding: 1px;" width="20%">'  . $currencies->format($popup_price) . '</td></tr>';
			} // line added
			} // line added
          }
        }
        $cart_contents_string .= '</table>';

        ob_start();
        include('includes/modules/content/' . $this->group . '/templates/modal_cart.php');
        $template = ob_get_clean();

        $oscTemplate->addContent($template, $this->group);

$script = <<<EOL
<script type="text/javascript">
      $(window).on('load', function (){
          $('#upCart').modal('show');
  });
</script>
EOL;
        $oscTemplate->addBlock($script, 'footer_scripts');
        tep_session_unregister('new_products_id_in_cart');
      }
    }

with OsC 2.2 since 2006 ...

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...