Jump to content



Photo
- - - - -

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


  • Please log in to reply
4 replies to this topic

#1 ONLINE   bonbec

bonbec
  • Members
  • 65 posts
  • Real Name:Fred
  • Gender:Male
  • Location:Vichy - France

Posted 13 April 2017 - 12:39

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.

Attached Files


Live   : OsC 2.2, php 5.2 & UTF-8

Local : OsC 234BS for future shop


#2 ONLINE   bonbec

bonbec
  • Members
  • 65 posts
  • Real Name:Fred
  • Gender:Male
  • Location:Vichy - France

Posted 13 April 2017 - 13:11

My idea is to use my tips : http://forums.oscomm...-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.


Live   : OsC 2.2, php 5.2 & UTF-8

Local : OsC 234BS for future shop


#3   frankl

frankl

    One of the originals...

  • Community Sponsor
  • 512 posts
  • Real Name:Frank
  • Gender:Male
  • Location:Sydney, Australia

Posted 14 April 2017 - 01:02

@bonbec What value is being returned for $new_products_id_in_cart and/or tep_session_is_registered('new_products_id_in_cart')?
 

Would that be useful?


Let's make things easier for new osCommerce users http://forums.oscomm...bles/?p=1718900  Getting there with osCommerce 2.4! :thumbsup:


#4 ONLINE   bonbec

bonbec
  • Members
  • 65 posts
  • Real Name:Fred
  • Gender:Male
  • Location:Vichy - France

Posted 14 April 2017 - 07:48

@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.


Live   : OsC 2.2, php 5.2 & UTF-8

Local : OsC 234BS for future shop


#5 ONLINE   bonbec

bonbec
  • Members
  • 65 posts
  • Real Name:Fred
  • Gender:Male
  • Location:Vichy - France

Posted 14 April 2017 - 13:18

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.

 


Edited by bonbec, 14 April 2017 - 13:19.

Live   : OsC 2.2, php 5.2 & UTF-8

Local : OsC 234BS for future shop