Пример #1
0
 /**
  * {@inheritdoc}
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     if ($oppositeRecord->getValue($this->field) !== null || $this->setNullIfEmpty) {
         $recordToHandle->setValue($this->field, $oppositeRecord->getValue($this->field));
     }
 }
Пример #2
0
 /**
  * {@inheritdoc}
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $value = $recordToHandle->getValue($this->field);
     $valueOpposite = $oppositeRecord->getValue($this->field);
     if (!is_numeric($value) && $valueOpposite) {
         $value = $valueOpposite;
     }
     $recordToHandle->setValue($this->field, $value);
 }
 /**
  * @param Record $recordToHandle
  * @param Record $oppositeRecord
  * @return void
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $sourceModel = $recordToHandle->getValue($this->field);
     $oppositeRecordValue = $oppositeRecord->getValue($this->field);
     if (empty($sourceModel) && !empty($oppositeRecordValue)) {
         $recordToHandle->setValue($this->field, $oppositeRecord->getValue($this->field));
     } elseif (empty($sourceModel) || $recordToHandle->getValue('is_configurable')) {
         $recordToHandle->setValue($this->field, null);
     }
 }
Пример #4
0
 /**
  * Add Record to collection
  *
  * @param \Migration\Resource\Record $record
  * @return $this
  * @throws Exception
  */
 public function addRecord($record)
 {
     if (!$record->getStructure()) {
         $record->setStructure($this->structure);
     }
     if (!$record->validateStructure($this->structure)) {
         throw new Exception("Record structure does not equal Collection structure");
     }
     $this->data[] = $record;
     return $this;
 }
Пример #5
0
 /**
  * @param Record $recordToHandle
  * @param Record $oppositeRecord
  * @return mixed
  */
 public function handle(Record $recordToHandle, Record $oppositeRecord)
 {
     $this->validate($recordToHandle);
     $sourceModel = $recordToHandle->getValue($this->field);
     $oppositeRecordValue = $oppositeRecord->getValue($this->field);
     if (empty($sourceModel) && !empty($oppositeRecordValue)) {
         $recordToHandle->setValue($this->field, $oppositeRecord->getValue($this->field));
     } elseif (empty($sourceModel)) {
         $recordToHandle->setValue($this->field, null);
     } else {
         $recordToHandle->setValue($this->field, $this->classMap->convertClassName($sourceModel));
     }
 }
Пример #6
0
 /**
  * @dataProvider stateProvider
  * @param string $state
  */
 public function testHandleVisibleState($state)
 {
     $fieldName = 'visible_on_front';
     $this->recordToHandle->expects($this->once())->method('getFields')->will($this->returnValue([$fieldName]));
     $this->recordToHandle->expects($this->any())->method('getValue')->will($this->returnCallback(function ($value) use($state) {
         switch ($value) {
             case 'status':
                 return 'some_my_status';
                 break;
             case 'state':
                 return $state;
                 break;
         }
         return '';
     }));
     $this->recordToHandle->expects($this->once())->method('setValue')->with($fieldName, 1);
     $handler = new SetVisibleOnFront();
     $handler->setField($fieldName);
     $handler->handle($this->recordToHandle, $this->oppositeRecord);
 }
Пример #7
0
 /**
  * @param Record $sourceRecord
  * @param array $keyFields
  * @return string
  */
 protected function getMappingValue(Record $sourceRecord, $keyFields)
 {
     $value = [];
     foreach ($keyFields as $field) {
         switch ($field) {
             case 'attribute_id':
                 $value[] = $this->getDestinationAttributeId($sourceRecord->getValue($field));
                 break;
             default:
                 $value[] = $sourceRecord->getValue($field);
                 break;
         }
     }
     return implode('-', $value);
 }
Пример #8
0
 /**
  * @param Record $from
  * @param Record $to
  * @return void
  */
 protected function copy(Record $from, Record $to)
 {
     $sourceDocumentName = $this->sourceDocument->getName();
     $data = $from->getData();
     $sourceFields = $from->getFields();
     $destinationFields = $to->getFields();
     $diff = array_diff($sourceFields, $destinationFields);
     foreach ($diff as $field) {
         if (!$this->mapReader->isFieldIgnored($sourceDocumentName, $field, MapInterface::TYPE_SOURCE)) {
             $fieldMap = $this->mapReader->getFieldMap($sourceDocumentName, $field, MapInterface::TYPE_SOURCE);
             $data[$fieldMap] = $from->getValue($field);
         }
         unset($data[$field]);
     }
     $to->setData($data);
 }
Пример #9
0
 /**
  * @param Resource\Record $destinationRecord
  * @param array $recordData
  * @return Resource\Record
  */
 protected function transformRecord($destinationRecord, $recordData)
 {
     foreach ($destinationRecord->getFields() as $recordField) {
         $destinationRecord->setValue($recordField, $recordData[$recordField]);
     }
     return $destinationRecord;
 }
Пример #10
0
 /**
  * @param Record $record
  * @return mixed
  */
 public function getRecordEntityType(Record $record)
 {
     $isCategory = $record->getValue('category_id') ? 'category' : null;
     $isProduct = $record->getValue('product_id') ? 'product' : null;
     return $isProduct ?: $isCategory;
 }
Пример #11
0
 public function testGetFieldsInvalid()
 {
     $this->record->setStructure(null);
     $this->setExpectedException('Exception', 'Structure not set');
     $this->record->getFields();
 }
 /**
  * @param Record $from
  * @param Record $to
  * @return void
  */
 protected function copy(Record $from, Record $to)
 {
     foreach ($from->getFields() as $field) {
         if (!$this->mapReader->isFieldIgnored($this->sourceDocument->getName(), $field, MapInterface::TYPE_SOURCE)) {
             $fieldMap = $this->mapReader->getFieldMap($this->sourceDocument->getName(), $field, MapInterface::TYPE_SOURCE);
             $to->setValue($fieldMap, $from->getValue($field));
         }
     }
 }
Пример #13
0
 /**
  * {@inheritdoc}
  */
 public function validate(Record $record)
 {
     if (!in_array($this->field, $record->getFields())) {
         throw new Exception("{$this->field} field not found in the record.");
     }
 }