0

I apologize ahead of time for the crappy question title I couldnt figure out a good way to summarize the solution Im looking for in a sentence.

Platform is Magento/PHP but the Magento part isnt really a part of this problem. Basically we have a service at checkout (just a dropdown box) for customers to select a future date for their order to ship. Ive been tasked with limiting the display of this service to only a few products.

  • If an order contains one or more of a permitted product, or, several of the products that are permitted it would display the dropdown box.

  • If the order contains a mix of permitted and non-permitted products obviously it would not show the dropdown box.

I created a new product attribute called "can_futureship" and set the value to True for the few products that are permitted to ship on a future date. My problem now is I cant seem to grasp the best way to single out those products.

There is a chunk of code (foreach loop) that goes through all the items in the cart and checks them for other restrictions and attributes so I know I need to put it in that loop. Especially in the cases of mixed True and False conditions. For example some pseudocode:

Product1 = True
Product2 = True
Product3 = True

$can_futureship_show_drop_down = false;

foreach(Items as item) {

  $product['can_futureship'] = model->getattribute('can_futureship');
  if ($product['can_futureship'] = TRUE) {
       $can_futureship_show_drop_down = true;
    }
 }

That was my initial line of thinking and would obviously work if all the products are true or the last product in the array is true but I need it to end up false if there any false results at all. I was also thinking that maybe I should load all results into an array and check for false results that way? Any help is greatly appreciated!

4

1 回答 1

1

换个方式想;)

$can_ship_future = true;
foreach($products as $product) {
    if ( ! $product->canShipFuture() ) {
         $can_ship_future = false;
         break; // Don't need to check the other products
    }
}
于 2013-10-22T15:44:17.177 回答