Jump to content
  • Checkout
  • Login
  • Get in touch

osCommerce

The e-commerce.

Getting an array in classes/Shopping_cart


Sumisu

Recommended Posts

This sounds like it's really simple, lord knows it should be...

 

If you print_r($products) from the catalog/Shopping_cart.php... that is the array I'm trying to work with... only from the catalog/includes/classes/Shopping_cart.php.

 

What I'm trying to do is look for a product that is duplicating under two contributions conflicting, and if its already in the cart then dont update the $product_array in catalog/includes/classes/Shopping_cart.php... if it isnt already there, go ahead and add to $products_array.

 

for some reason, I've tried using $this->contents, $products and $products_array direct in a double nested foreach to place me on the correct layer then check a value is in_array and I'm either recieving errors saying - sucha thing was expecting and array, something is NULL... or my test IF statements return false where the obviously should be returning true and not a lot is happening --- now --- I've tested all the code on a blank php file where I've printed the array and manually included it - an EXACT match from the print_r.. IT ALL WORKS!!!.. put code into oscommerce, and NOTHING..

 

I have used ints against my variables at various points to test where the problem lies.. It's definately due to me not calling the correct product array properly.

 

Could somebody please please help! just try print_r($products) on your catalog/Shopping_cart.php.. THATS THE ARRAY I WANT... how do I retrieve THAT data from catalog/includes/classes/Shopping_cart.php? I NEED THE FULL CART CONTENTS to chack if particular values exist... thats it! why is this so difficult?

 

I hope this isnt complicated :)

 

Thanks in advance

 

Martin

Link to comment
Share on other sites

Sumisu

 

Try following function into catalog/includes/classes/Shopping_cart.php

 

public function exists($product_id) {

foreach ( $this->_contents as $product ) {

if ( $product['id'] == $product_id ) {

if ( isset($product['variants']) ) {

foreach ( $product['variants'] as $variant ) {

if ( $variant['has_custom_value'] === true ) {

return false;

}

}

}

 

return true;

}

}

 

return false;

}

 

 

Regards

Anna!

Link to comment
Share on other sites

Ok, understood.. I thought it might have been a common mistake I was making... so here goes, this is what I'm trying to do

 

In order to get 'QTPro' and 'Get 1 Free' working together, I've already done everything else to check and sum quantities correctly, most of the hard work is done... this is all that's left -

 

The array and what I'm trying to do with it:

 

the-array.jpg

 

right... where it needs to go in the classes/shopping_cart.php

 

shopping_cart.jpg

 

Hope that makes everything 100% clear

 

Thanks for your help! everything I've tried has failed so far --- i can do it when I test on a blank php file but for some reason oscommerce has a problem with the way I'm doing it.. any advice you could give would be fantastic!!! it's been driving me mad this bit --- right when I'm nearly finished aswell!!! haha

 

Cheers

Martin

Link to comment
Share on other sites

@@Sumisu

 

Not sure what you mean Martin.

 

It's not QTPro adding the attributes to the product id .. this is a standard function of osCommerce when adding to cart a product which has attributes.

Link to comment
Share on other sites

OH, well I didnt know that, QTPro has been an early install for all my websites, never actually looked at array without it... but nether the less, becuase each attribute is being seperated in the shopping cart, Get1Free is re-adding its free product to the $products_array. So If I have a buy 2 jumpers, get a tshirt free.. and somebody buys 1 medium jumper and 1 large jumper, because they're seperated in the cart, its giving free product under 1 jumper medium, and then when jumper large gets added to the array, it adds it again! This is what I'm doing the check for to see if it's already in the $products_array, and if so, dont add it to the array.

Link to comment
Share on other sites

thanks for the advice.. no I hadnt considered them.

 

However... time to slap myself silly across the face... I've been trying to do an IF statement to check the array within a while before the array has even been completed and returned :) duh

 

hahaha, I've wasted days on this... it's fine now I'm going about it from an entirely different angle now.

 

thanks for all your imput

Link to comment
Share on other sites

Archived

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

×
×
  • Create New...