You are here

public function XquantityOrderItem::getItemsQuantity in Commerce Extended Quantity 8

File

src/Entity/XquantityOrderItem.php, line 49

Class

XquantityOrderItem
Overrides the order item entity class.

Namespace

Drupal\commerce_xquantity\Entity

Code

public function getItemsQuantity() {
  $settings = $this
    ->getQuantityWidgetSettings();

  // The #step value defines the actual type of the current order item's
  // quantity field. If that is int then we consider the quantity as a sum of
  // order items. If float, then we consider the quantity as one item
  // consisting of multiple units. For example: 1 + 2 T-shirts are counted as
  // 3 separate items but 1.000 + 2.000 kg of butter is counted as 1 item
  // consisting of 3000 units. Hence, this method must be used only to count
  // items on an order. The $this->getQuantity() must be used for getting real
  // quantity disregarding of whatever the type of this number is, for example
  // to calculate the price of order items.
  $step = isset($settings['step']) && is_numeric($settings['step']) ? $settings['step'] + 0 : 1;
  $quantity = $this
    ->getQuantity();
  return (string) is_int($step) ? $quantity : (is_float($step) && $quantity > 0 ? '1' : $quantity);
}