0

I have this array:

object(stdClass)#458 (2) {
  ["1"]=>
  object(stdClass)#456 (3) {
    ["title"]=>
    string(3) "Test Product 1"
    ["quantity"]=>
    int(1)
    ["price"]=>
    int(1221)
  }
  ["shipping"]=>
  object(stdClass)#457 (3) {
    ["quantity"]=>
    int(1)
    ["title"]=>
    string(13) "Free Delivery"
    ["price"]=>
    int(0)
  }
}

I'm displaying this on the page like this.

@foreach($order->getOrderData($order->order_details) as $itemId => 
     <?php $total += ($item->price * $item->quantity); ?>
     <h4 class="media-heading">{{ $item->title }}</h4>
      {{ $item->quantity }}
      ${{ $item->price * $item->quantity }} / €{{ $order['total_eur'] }}
@endforeach

So far everything works perfect except the addition value which I call from database $order['total_eur']. This value is saved when order is placed so I then show total in USD and total in EUR.

The problem here is that ${{ $item->price * $item->quantity }} contain also shipping and when shipping is Free e.g. $ 0 is shown on page

Test Product 1   $122 /  €113      
Free Delivery    $0 / €113 

What I'm trying to do is to replace somehow when the delivery is free e.g. ["shipping"]=>["price"] = 0 to show 0 instead. to be like this:

Test Product 1   $122 /  €113      
Free Delivery    $0 / €0 

I can access it like this

<?php $shipping = $order->getOrderData($order->order_details)->shipping->price; ?>

But I can't figured it out how can I change it in the foreach loop.

I hope I explained this clear and understandable. Can anyone suggest something that may work?

Update: I've tried this simple if inside foreach but still showing both eur price on both

${{ $item->price * $item->quantity }} 
  @if( ! $order->getOrderData($order->order_details)->shipping) 
      {{ $order->getOrderData($order->order_details)->shipping->price }} 
  @else 
      €{{ $order['total_eur'] }} 
  @endif
3
  • Its quite confusing? A simple if would do inside foreach loop? Commented Mar 22, 2017 at 10:38
  • @SaravananSampathkumar, I've updated my question with the if condition I tried but still same Commented Mar 22, 2017 at 10:48
  • No, I mean check if price is zero, like @if($item->price) then it is free delivery, else normal one. Commented Mar 22, 2017 at 10:49

1 Answer 1

1
@foreach($order->getOrderData($order->order_details) as $itemId => $item)
     <?php $total += ($item->price * $item->quantity); ?>
     <h4 class="media-heading">{{ $item->title }}</h4>
      {{ $item->quantity }}
      @if ($itemId == "shipping" && $item->price == 0) 
        $0 / €0
      @else
        ${{ $item->price * $item->quantity }} / €{{ $order['total_eur'] }}
      @endif
@endforeach

Here we are checking the array whether it is shipping item and price is set to zero. If so we are displaying zero €, else we are displaying the actual cost.

Sign up to request clarification or add additional context in comments.

2 Comments

Yes, this is work for the question I've asked. I found out that there is something else that Is missing here. Thanks
But the delivery can be different from zero.. paid one. This mean with above code will show total_eur again

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.