1

This might be a simple solution, however I am not able to come up with it, therefore any help is welcome.

I have a shopping basket so customers can add different items for it (as normal) On some of these Items there are conditions and when added to the basket I'd like to show them up, however I have it setup so it checks for the value, but it only takes the value from the last added item.

Have the following

public function get_contents() {
$items = array();

        foreach($this->items as $tmpItem) {
            $item = null;
            $item['Condition']  = $this->Conditions[$tmpItem];
            $items[]          = $item;
        }
        return $items;
    }


    foreach($this->items as $item) {
        if(strstr($this->Conditions[$item], 'no') ==!false) {
            $this->Conditions = 'no';
            $item['Condition']      = $this->Conditions;
        } else  
            $this->Conditions = 'yes';
            $item['Condition']      = $this->Conditions;

What I would like to do is if any of these items contain the condition 'no'

  $this->Conditions = 'no';
  $item['Condition']      = $this->Conditions;

However it only takes the value of the last added item Any help welcome

11
  • Does your $this->items contains all items in cart ? Commented Jan 11, 2017 at 11:37
  • @Sunil Thank you for looking, yes I think it does Commented Jan 11, 2017 at 11:51
  • and after the foreach what does $this->items prints ? does it contains "Condition" in each item or only the last one ? Commented Jan 11, 2017 at 11:59
  • Only the last one Commented Jan 11, 2017 at 12:05
  • then i think the problem in the definition of the item arrays, have you checked that $item in the loop in a simple array and not an object ? Commented Jan 11, 2017 at 12:11

1 Answer 1

1

You are over riding the array element

foreach($this->items as $item) {
       if(strstr($this->Conditions[$item], 'no') ==!false){
       $this->Conditions = 'no';
       $item[]      = $this->Conditions;
       }
       else{   
       $this->Conditions = 'yes';
       $item[]      = $this->Conditions;
       }
}
Sign up to request clarification or add additional context in comments.

1 Comment

also if you need item with no tag you could try $item[$this->Conditions[$item]] = 'no'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.