drferrari Posted May 10, 2017 Share Posted May 10, 2017 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... Link to comment Share on other sites More sharing options...
drferrari Posted May 11, 2017 Author Share Posted May 11, 2017 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. Link to comment Share on other sites More sharing options...
Solomono Posted May 11, 2017 Share Posted May 11, 2017 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] Link to comment Share on other sites More sharing options...
drferrari Posted May 11, 2017 Author Share Posted May 11, 2017 @@Solomono, Can you explain me how exactly this work. thank you Link to comment Share on other sites More sharing options...
Solomono Posted May 11, 2017 Share Posted May 11, 2017 $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]; Link to comment Share on other sites More sharing options...
♥kymation Posted May 11, 2017 Share Posted May 11, 2017 To simplify that a bit: $cart_products = $cart->get_products( true ); $last_item = end( $cart_products ); Regards Jim See my profile for a list of my addons and ways to get support. Link to comment Share on other sites More sharing options...
drferrari Posted May 11, 2017 Author Share Posted May 11, 2017 @@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. Link to comment Share on other sites More sharing options...
drferrari Posted May 11, 2017 Author Share Posted May 11, 2017 :beer: for me too. echo $last_item[id]."<br>"; echo $last_item[quantity]; Link to comment Share on other sites More sharing options...
Solomono Posted May 12, 2017 Share Posted May 12, 2017 yes, you dont need to implode. Link to comment Share on other sites More sharing options...
burt Posted May 12, 2017 Share Posted May 12, 2017 Look at array_pop() - very useful inbuilt php function. Link to comment Share on other sites More sharing options...
drferrari Posted May 12, 2017 Author Share Posted May 12, 2017 @@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))); Link to comment Share on other sites More sharing options...
burt Posted May 12, 2017 Share Posted May 12, 2017 I don't understand what it is that you are trying to do. Link to comment Share on other sites More sharing options...
drferrari Posted May 12, 2017 Author Share Posted May 12, 2017 @@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. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.