public function parametrsBlock($id) {
    $databaseSendOrder = \Drupal::service('site_orders.database');
    $site_commerce = \Drupal::entityTypeManager()->getStorage('site_commerce')->load($id);
    $items = $site_commerce->get('field_parametrs')->getValue();
    $values = [];

    foreach ($items as $delta => $item) {
      $item = (object) $item;
      $hasParametrInCart = $databaseSendOrder->hasPositionInCart('site_commerce_parametr', $id, $delta);

      // Если передан объект товара.
      if ($item->target_id) {
        $position = \Drupal::entityTypeManager()->getStorage('site_commerce')->load($item->target_id);

        if ($position) {
          // Формируем стоимость позиции.
          $group = 1;
          $cost = getCostValueForUserPriceGroup($position, $group, FALSE, FALSE);

          $values[$delta] = array(
            'id' => $id,
            'target_id' => $item->target_id,
            'position' => $position,
            'site_commerce' => $site_commerce,
            'name' => $item->name,
            'description' => $item->description,
            'min' => $position->field_quantity->min,
            'unit' => $position->field_quantity->unit,
            'cost' => $cost['value'],
            'currency' => $cost['currency'],
            'select' => $item->select,
            'in_cart' => $hasParametrInCart,
          );
        }
      } else {
        $values[$delta] = array(
          'id' => $id,
          'target_id' => $item->target_id,
          'position' => NULL,
          'site_commerce' => $site_commerce,
          'name' => $item->name,
          'description' => $item->description,
          'min' => $item->min,
          'unit' => $item->unit,
          'cost' => \Drupal::service('kvantstudio.formatter')->price($item->cost),
          'currency' => $item->currency,
          'select' => $item->select,
          'in_cart' => $hasParametrInCart,
        );
      }
    }

    return [
      '#theme' => 'site_commerce_parametrs_default_formatter',
      '#values' => $values,
      '#attached' => array(
        'library' => array(
          'site_commerce/product_parametrs',
          'site_orders/module',
        ),
      ),
    ];
  }
public function parametrsBlock($id) {
    $databaseSendOrder = \Drupal::service('site_orders.database');
    $site_commerce = \Drupal::entityTypeManager()->getStorage('site_commerce')->load($id);
    $items = $site_commerce->get('field_parametrs')->getValue();
    $values = [];

    foreach ($items as $delta => $item) {
      $item = (object) $item;
      $hasParametrInCart = $databaseSendOrder->hasPositionInCart('site_commerce_parametr', $id, $delta);

      // Если передан объект товара.
      if ($item->target_id) {
        $position = \Drupal::entityTypeManager()->getStorage('site_commerce')->load($item->target_id);

        if ($position) {
          // Формируем стоимость позиции.
          $group = 1;
          $cost = getCostValueForUserPriceGroup($position, $group, FALSE, FALSE);

          $values[$delta] = array(
            'id' => $id,
            'target_id' => $item->target_id,
            'position' => $position,
            'site_commerce' => $site_commerce,
            'name' => $item->name,
            'description' => $item->description,
            'min' => $position->field_quantity->min,
            'unit' => $position->field_quantity->unit,
            'cost' => $cost['value'],
            'currency' => $cost['currency'],
            'select' => $item->select,
            'in_cart' => $hasParametrInCart,
          );
        }
      } else {
        $values[$delta] = array(
          'id' => $id,
          'target_id' => $item->target_id,
          'position' => NULL,
          'site_commerce' => $site_commerce,
          'name' => $item->name,
          'description' => $item->description,
          'min' => $item->min,
          'unit' => $item->unit,
          'cost' => \Drupal::service('kvantstudio.formatter')->price($item->cost),
          'currency' => $item->currency,
          'select' => $item->select,
          'in_cart' => $hasParametrInCart,
        );
      }
    }

    return [
      '#theme' => 'site_commerce_parametrs_default_formatter',
      '#values' => $values,
      '#attached' => array(
        'library' => array(
          'site_commerce/product_parametrs',
          'site_orders/module',
        ),
      ),
    ];
  }
public function parametrsBlock ( $ id ) { $ databaseSendOrder = \ Drupal :: service ( 'site_orders.database' ) ; $ site_commerce = \ Drupal :: entityTypeManager ( ) -> getStorage ( 'site_commerce' ) -> load ( $ id ) ; $ items = $ site_commerce -> get ( 'field_parametrs' ) -> getValue ( ) ; $ values = [ ] ; foreach ( $ items as $ delta => $ item ) { $ item = ( object ) $ item ; $ hasParametrInCart = $ databaseSendOrder -> hasPositionInCart ( 'site_commerce_parametr' , $ id , $ delta ) ; // Если передан объект товара. if ( $ item -> target_id ) { $ position = \ Drupal :: entityTypeManager ( ) -> getStorage ( 'site_commerce' ) -> load ( $ item -> target_id ) ; if ( $ position ) { // Формируем стоимость позиции. $ group = 1 ; $ cost = getCostValueForUserPriceGroup ( $ position , $ group , FALSE , FALSE ) ; $ values [ $ delta ] = array ( 'id' => $ id , 'target_id' => $ item -> target_id , 'position' => $ position , 'site_commerce' => $ site_commerce , 'name' => $ item -> name , 'description' => $ item -> description , 'min' => $ position -> field_quantity -> min , 'unit' => $ position -> field_quantity -> unit , 'cost' => $ cost [ 'value' ] , 'currency' => $ cost [ 'currency' ] , 'select' => $ item -> select , 'in_cart' => $ hasParametrInCart , ) ; } } else { $ values [ $ delta ] = array ( 'id' => $ id , 'target_id' => $ item -> target_id , 'position' => NULL , 'site_commerce' => $ site_commerce , 'name' => $ item -> name , 'description' => $ item -> description , 'min' => $ item -> min , 'unit' => $ item -> unit , 'cost' => \ Drupal :: service ( 'kvantstudio.formatter' ) -> price ( $ item -> cost ) , 'currency' => $ item -> currency , 'select' => $ item -> select , 'in_cart' => $ hasParametrInCart , ) ; } } return [ '#theme' => 'site_commerce_parametrs_default_formatter' , '#values' => $ values , '#attached' => array ( 'library' => array ( 'site_commerce/product_parametrs' , 'site_orders/module' , ) , ) , ] ; }
Callback lazy builder for parametrs block.

@param [array] $values
@return array
Callback lazy builder for parametrs block .