Jump to content
Psytanium

Shopping cart content class

Recommended Posts

Hi,

In shopping_cart.php class, i can find $this->contents[$products_id]['qty'], but where did it get its value ? possible to create $this->contents[$products_id]['price'] ?

Thank you

Share this post


Link to post
Share on other sites

It's inadvisable to add more columns to cart->contents, as it is stored in the session.  That's why price and other characteristics are loaded by get_products rather than stored in the cart. 

If you are making custom attributes, consider changing the products ID.  That's how that has typically been implemented in the past.  Or consider doing something like product bundles where the user sees one product but behind the scenes there is more than one. 

The quantity is set in includes/actions. 


Always back up before making changes.

Share this post


Link to post
Share on other sites
11 hours ago, ecartz said:

It's inadvisable to add more columns to cart->contents, as it is stored in the session.  That's why price and other characteristics are loaded by get_products rather than stored in the cart. 

If you are making custom attributes, consider changing the products ID.  That's how that has typically been implemented in the past.  Or consider doing something like product bundles where the user sees one product but behind the scenes there is more than one. 

The quantity is set in includes/actions

Thank you for explaining this issue, in the file i want to modify this function :

function count_contents() { // get total number of items in cart
      $total_items = 0;
      if (is_array($this->contents)) {
        reset($this->contents);
        while (list($products_id, ) = each($this->contents)) {
          $total_items += $this->get_quantity($products_id);
        }
      }

For some reasons, i want to count specific file and do something similar to

function count_contents() { // get total number of items in cart
      $total_items = 0;
      if (is_array($this->contents)) {
        reset($this->contents);
        while (list($products_id, ) = each($this->contents)) {
			// modification to count specific products
			if ($this->contents[$products_id]['newfield'] == 1) {
				$total_items += $this->get_quantity($products_id);
			}
        }
      }

any possible solution ? thanks

btw i didn't find includes/action in my directories, i'm working on 2.3.4

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

×