Change shipping preference if purchase units does not contain shipping

This commit is contained in:
dinamiko 2021-10-15 16:16:54 +02:00
parent 79e2dd2ef5
commit 3295488b29

View file

@ -193,6 +193,10 @@ class OrderEndpoint {
: ApplicationContext::SHIPPING_PREFERENCE_GET_FROM_FILE
: ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
if ( $this->items_without_shipping( $items ) ) {
$shipping_preferences = ApplicationContext::SHIPPING_PREFERENCE_NO_SHIPPING;
}
$bearer = $this->bearer->bearer();
$data = array(
'intent' => $this->intent,
@ -572,4 +576,20 @@ class OrderEndpoint {
$new_order = $this->order( $order_to_update->id() );
return $new_order;
}
/**
* Checks if items contains shipping.
*
* @param array $items The items.
* @return bool Whether items contains shipping or not.
*/
private function items_without_shipping( array $items ): bool {
foreach ( $items as $item ) {
if ( ! $item->shipping() ) {
return true;
}
}
return false;
}
}