You are here

protected static function PriceListItemExportForm::buildRow in Commerce Pricelist 8.2

Builds the CSV row for the given price list item.

Parameters

\Drupal\commerce_pricelist\Entity\PriceListItemInterface $price_list_item: The price list item.

array $header_mapping: The CSV header mapping.

Return value

array The CSV row for the given price list item.

1 call to PriceListItemExportForm::buildRow()
PriceListItemExportForm::batchProcess in src/Form/PriceListItemExportForm.php
Batch process to export price list items to CSV.

File

src/Form/PriceListItemExportForm.php, line 338

Class

PriceListItemExportForm

Namespace

Drupal\commerce_pricelist\Form

Code

protected static function buildRow(PriceListItemInterface $price_list_item, array $header_mapping) {
  $purchased_entity = $price_list_item
    ->getPurchasableEntity();
  $id = $price_list_item
    ->bundle() === 'commerce_product_variation' ? $purchased_entity
    ->getSku() : $purchased_entity
    ->id();
  $list_price = '';
  if ($price_list_item
    ->getListPrice()) {
    $list_price = $price_list_item
      ->getListPrice()
      ->getNumber();
  }
  $row = [
    $id,
  ];

  // Include the title if it wasn't excluded from the export.
  if (!empty($header_mapping['purchasable_entity_label_column'])) {
    $row[] = $purchased_entity
      ->label();
  }
  return array_merge($row, [
    $price_list_item
      ->getQuantity(),
    $list_price,
    $price_list_item
      ->getPrice()
      ->getNumber(),
    $price_list_item
      ->getPrice()
      ->getCurrencyCode(),
  ]);
}