/**
  * Record transformer
  *
  * @param Record $record
  * @param Record $destRecord
  * @return void
  */
 private function transform(Record $record, Record $destRecord)
 {
     $destRecord->setValue('url_rewrite_id', $record->getValue('url_rewrite_id'));
     $destRecord->setValue('store_id', $record->getValue('store_id'));
     $destRecord->setValue('description', $record->getValue('description'));
     $destRecord->setValue('request_path', $record->getValue('request_path'));
     $destRecord->setValue('target_path', $record->getValue('target_path'));
     $destRecord->setValue('is_autogenerated', $record->getValue('is_system'));
     $destRecord->setValue('entity_type', $this->getRecordEntityType($record));
     $metadata = $this->doRecordSerialization($record) ? serialize(['category_id' => $record->getValue('category_id')]) : null;
     $destRecord->setValue('metadata', $metadata);
     $destRecord->setValue('entity_id', $record->getValue('product_id') ?: $record->getValue('category_id'));
     $destRecord->setValue('redirect_type', $this->redirectTypesMapping[$record->getValue('options')]);
 }
 /**
  * @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]);
     }
     foreach ($data as $key => $value) {
         $to->setValue($key, $value);
     }
 }
Exemplo n.º 3
0
 /**
  * @param ResourceModel\Record $destinationRecord
  * @param array $recordData
  * @return ResourceModel\Record
  */
 protected function transformRecord($destinationRecord, $recordData)
 {
     foreach ($destinationRecord->getFields() as $recordField) {
         $destinationRecord->setValue($recordField, $recordData[$recordField]);
     }
     return $destinationRecord;
 }
 /**
  * @expectedException \Migration\Exception
  * @expectedExceptionMessage Record structure does not contain field wrongField
  * @return void
  */
 public function testSetValueWithException()
 {
     $this->record->setStructure($this->structure);
     $this->record->setValue('wrongField', 'itemNew');
 }