Example #1
0
 public function testPrepareWithAlreadyAddedComponent()
 {
     $attributeCode = 'billing_attribute_code';
     $attributeData = ['attribute_code' => $attributeCode, 'frontend_input' => 'frontend-input', 'frontend_label' => 'frontend-label', 'backend_type' => 'backend-type', 'options' => [['label' => 'Label', 'value' => 'Value']], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => false, 'is_searchable_in_grid' => true];
     $this->component->addComponent($attributeCode, $this->filter);
     $this->attributeRepository->expects($this->atLeastOnce())->method('getList')->willReturn([$attributeCode => $attributeData]);
     $this->component->prepare();
     $this->assertEquals(null, $this->component->getComponent($attributeCode));
 }
 public function testPrepareDataSource()
 {
     $genderOptionId = 1;
     $genderOptionLabel = 'Male';
     $dataSource = ['data' => ['items' => [['name' => 'testName'], ['gender' => $genderOptionId]]]];
     $expectedSource = ['data' => ['items' => [['name' => 'testName'], ['gender' => $genderOptionLabel]]]];
     $this->attributeRepository->expects($this->once())->method('getMetadataByCode')->with('gender')->willReturn(['attribute_code' => 'billing_attribute_code', 'frontend_input' => 'frontend-input', 'frontend_label' => 'frontend-label', 'backend_type' => 'backend-type', 'options' => [['label' => $genderOptionLabel, 'value' => $genderOptionId]], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true]);
     $dataSource = $this->component->prepareDataSource($dataSource);
     $this->assertEquals($expectedSource, $dataSource);
 }
 /**
  * {@inheritdoc}
  */
 public function getData()
 {
     $data = parent::getData();
     foreach ($this->attributeRepository->getList() as $attributeCode => $attributeData) {
         foreach ($data['items'] as &$item) {
             if (isset($item[$attributeCode]) && !empty($attributeData[AttributeMetadataInterface::OPTIONS])) {
                 $item[$attributeCode] = explode(',', $item[$attributeCode]);
             }
         }
     }
     return $data;
 }
Example #4
0
 /**
  * {@inheritdoc}
  */
 public function prepare()
 {
     $this->columnSortOrder = $this->getDefaultSortOrder();
     foreach ($this->attributeRepository->getList() as $newAttributeCode => $attributeData) {
         if (isset($this->components[$newAttributeCode])) {
             $this->updateColumn($attributeData, $newAttributeCode);
         } elseif (!$attributeData[AttributeMetadata::BACKEND_TYPE] != 'static' && $attributeData[AttributeMetadata::IS_USED_IN_GRID]) {
             $this->addColumn($attributeData, $newAttributeCode);
         }
     }
     $this->updateActionColumnSortOrder();
     parent::prepare();
 }
Example #5
0
 public function testPrepareWithUpdateStaticColumn()
 {
     $attributeCode = 'billing_attribute_code';
     $backendType = 'static';
     $attributeData = ['attribute_code' => 'billing_attribute_code', 'frontend_input' => 'text', 'frontend_label' => 'frontend-label', 'backend_type' => $backendType, 'options' => [['label' => 'Label', 'value' => 'Value']], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true, 'validation_rules' => [], 'required' => false, 'entity_type_code' => 'customer'];
     $this->inlineEditUpdater->expects($this->once())->method('applyEditing')->with($this->column, 'text', [], false);
     $this->attributeRepository->expects($this->atLeastOnce())->method('getList')->willReturn([$attributeCode => $attributeData]);
     $this->columnFactory->expects($this->once())->method('create')->willReturn($this->column);
     $this->column->expects($this->once())->method('prepare');
     $this->column->expects($this->atLeastOnce())->method('getData')->with('config')->willReturn(['editor' => 'text']);
     $this->column->expects($this->at(3))->method('setData')->with('config', ['editor' => 'text', 'options' => [['label' => 'Label', 'value' => 'Value']]]);
     $this->column->expects($this->at(6))->method('setData')->with('config', ['editor' => 'text', 'visible' => true]);
     $this->component->addColumn($attributeData, $attributeCode);
     $this->component->prepare();
 }
 /**
  * Prepare Data Source
  *
  * @param array $dataSource
  * @return array
  */
 public function prepareDataSource(array $dataSource)
 {
     $metaData = $this->attributeRepository->getMetadataByCode($this->getName());
     if ($metaData && count($metaData[AttributeMetadata::OPTIONS])) {
         foreach ($dataSource['data']['items'] as &$item) {
             if (!isset($item[$this->getName()])) {
                 continue;
             }
             foreach ($metaData[AttributeMetadata::OPTIONS] as $option) {
                 if ($option['value'] == $item[$this->getName()]) {
                     $item[$this->getName()] = $option['label'];
                     break;
                 }
             }
         }
     }
     return $dataSource;
 }
 public function testGetList()
 {
     $attributeCode = 'attribute_code';
     $billingPrefix = 'billing_';
     $this->customerMetadata->expects($this->once())->method('getAllAttributesMetadata')->willReturn([]);
     $this->addressMetadata->expects($this->once())->method('getAllAttributesMetadata')->willReturn([$this->attribute]);
     $this->addressMetadataManagement->expects($this->once())->method('canBeFilterableInGrid')->with($this->attribute)->willReturn(true);
     $this->addressMetadataManagement->expects($this->once())->method('canBeSearchableInGrid')->with($this->attribute)->willReturn(true);
     $this->attribute->expects($this->atLeastOnce())->method('getAttributeCode')->willReturn($attributeCode);
     $this->attribute->expects($this->once())->method('getFrontendInput')->willReturn('frontend-input');
     $this->attribute->expects($this->once())->method('getFrontendLabel')->willReturn('frontend-label');
     $this->attribute->expects($this->once())->method('getBackendType')->willReturn('backend-type');
     $this->attribute->expects($this->once())->method('getOptions')->willReturn([$this->option]);
     $this->attribute->expects($this->once())->method('getIsUsedInGrid')->willReturn(true);
     $this->attribute->expects($this->once())->method('getIsVisibleInGrid')->willReturn(true);
     $this->attribute->expects($this->once())->method('getValidationRules')->willReturn([]);
     $this->attribute->expects($this->once())->method('isRequired')->willReturn(false);
     $this->option->expects($this->once())->method('getLabel')->willReturn('Label');
     $this->option->expects($this->once())->method('getValue')->willReturn('Value');
     $this->attributeFilter->expects($this->once())->method('filter')->willReturnArgument(0);
     $this->assertEquals([$billingPrefix . $attributeCode => ['attribute_code' => 'billing_attribute_code', 'frontend_input' => 'frontend-input', 'frontend_label' => 'frontend-label', 'backend_type' => 'backend-type', 'options' => [['label' => 'Label', 'value' => 'Value']], 'is_used_in_grid' => true, 'is_visible_in_grid' => true, 'is_filterable_in_grid' => true, 'is_searchable_in_grid' => true, 'validation_rules' => [], 'required' => false, 'entity_type_code' => 'customer_address']], $this->component->getList());
 }