You are here

private function CartUnifier::shouldCombineItem in Commerce Combine Carts 8

Determine if a line item should be combined with like items.

Parameters

OrderItemInterface $item: The order item.

Return value

bool TRUE if items should be combined, FALSE otherwise.

1 call to CartUnifier::shouldCombineItem()
CartUnifier::combineCarts in src/CartUnifier.php
Combines another cart into the main cart and optionally deletes the other cart.

File

src/CartUnifier.php, line 163

Class

CartUnifier

Namespace

Drupal\commerce_combine_carts

Code

private function shouldCombineItem(OrderItemInterface $item) {

  /** @var \Drupal\commerce_product\Entity\ProductVariationInterface $purchased_entity */
  $purchased_entity = $item
    ->getPurchasedEntity();

  // Do not combine products which are no longer available in system.
  if (!$purchased_entity instanceof ProductVariationInterface) {
    return FALSE;
  }
  $product = $purchased_entity
    ->getProduct();
  $entity_display = EntityViewDisplay::load($product
    ->getEntityTypeId() . '.' . $product
    ->bundle() . '.default');
  $combine = TRUE;
  if ($component = $entity_display
    ->getComponent('variations')) {
    $combine = !empty($component['settings']['combine']);
  }
  return $combine;
}