Jump to content



Photo
- - - - -

Getting an array in classes/Shopping_cart


This topic has been archived. This means that you cannot reply to this topic.
7 replies to this topic

#1   Sumisu

Sumisu
  • Members
  • 34 posts

Posted 23 August 2012 - 02:37

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 /smile.png' class='bbc_emoticon' alt=':)' />

Thanks in advance

Martin

#2   annasmith

annasmith
  • Members
  • 4 posts

Posted 23 August 2012 - 08:48

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!

#3   burt

burt

    Vanquisher of Demons

  • Community Team
  • 9,544 posts

Posted 23 August 2012 - 11:22

You should state the precise data that you need to pull from the array.


.

Responsive osCommerce, join in the fun:
http://forums.oscomm...rom-the-get-go/

--
Making your shop better, one osCommerce module at a time - get in touch, or get my newsletter every 1st of the month.

 

Big Bang Templates for 2.3.4


#4   Sumisu

Sumisu
  • Members
  • 34 posts

Posted 23 August 2012 - 15:51

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:

[img]http://www.bantaz-projects.com/the-array.jpg[/img]

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

[img]http://www.bantaz-projects.com/shopping_cart.jpg[/img]

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

Edited by Sumisu, 23 August 2012 - 15:54.


#5   FWR Media

FWR Media
  • Members
  • 6,839 posts

Posted 23 August 2012 - 17:08

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

#6   Sumisu

Sumisu
  • Members
  • 34 posts

Posted 23 August 2012 - 18:13

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.

#7   burt

burt

    Vanquisher of Demons

  • Community Team
  • 9,544 posts

Posted 23 August 2012 - 18:42

Have you looked at the get_product_id_list() function?
Or the in_cart() function?


.

Responsive osCommerce, join in the fun:
http://forums.oscomm...rom-the-get-go/

--
Making your shop better, one osCommerce module at a time - get in touch, or get my newsletter every 1st of the month.

 

Big Bang Templates for 2.3.4


#8   Sumisu

Sumisu
  • Members
  • 34 posts

Posted 23 August 2012 - 21:42

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 /smile.png' class='bbc_emoticon' alt=':)' /> 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

Edited by Sumisu, 23 August 2012 - 21:43.