Latest News: (loading..)
drferrari

Values when product add to shopping cart

13 posts in this topic

Hello,

 

In product_info.php page ONLY when I click on ad to cart button I wanna see in shopping_cart.php page, and ONLY THE LAST product id product name, product quantity, price, product category.

 

I thinking something in application_top.php in case 'add_product' : when redirect apply: tep_redirect(tep_href_link($goto, tep_get_all_get_params($parameters)));

 

any idea how can this work...

Share this post


Link to post
Share on other sites

in application_top.php (case 'add_product') I insert values to redirect url

 

tep_redirect(tep_href_link($goto, 'prid='.$_POST['products_id'] . '&quantity=' . $_POST['cart_quantity']));

 

and then in shopping_cart.php page I get this values.

 

IS POSIBLE on some way hide this values and then get it in shopping_cart.php page.

Share this post


Link to post
Share on other sites

when you add product to shopping cart, it adds pid to session, so, you can get last product array by $cart->get_products(true)[count($cart->get_products(true))-1]

Share this post


Link to post
Share on other sites

$cart->get_products(true) - shows array with products, added to shopping cart. this is function get_products from class includes/classes/shopping_cart.php

this array is sorted from older to newer item, added to cart. so, last added item to cart its last element of array $cart->get_products(true)

to get last element of array, we use "count($some_array)-1", in our case its count($cart->get_products(true))-1

 

other words, we could write like this:

$cart_products = $cart->get_products(true);
$last_count = count($cart_products)-1;
$last_item = $cart_products[$last_count];
drferrari likes this

Share this post


Link to post
Share on other sites

To simplify that a bit:

$cart_products = $cart->get_products( true );
$last_item = end( $cart_products );

Regards

Jim

drferrari likes this

Share this post


Link to post
Share on other sites

@@Solomono and @@kymation for both  :beers: and thank you.

 

with this code echo $withComma = implode(",", $last_item); I get everything separated with comma.

 

Now I try get only e.g. name echo $products_array['name'] or quantity $products_array['quantity'], any idea.

Share this post


Link to post
Share on other sites

:beer: for me too.

echo $last_item[id]."<br>";
echo $last_item[quantity];

Share this post


Link to post
Share on other sites

Look at array_pop() - very useful inbuilt php function.

Share this post


Link to post
Share on other sites

@@burt Can you give me some example.

 

and is possible show last products ONLY when I click on add to cart button, is right to pass some value to

tep_redirect(tep_href_link($goto 'value=showlastproducts', tep_get_all_get_params($parameters)));

Share this post


Link to post
Share on other sites

I don't understand what it is that you are trying to do.

Share this post


Link to post
Share on other sites

@@burt the problem is every time I goto shopping_cart.php page I see the last product.

@[member=kymation]
$cart_products = $cart->get_products( true );
$last_item = end( $cart_products );

I wanna see it only when I add one product to cart.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now