コード例 #1
0
 /**
  * Add Name to select
  *
  * @return $this
  */
 public function addNameToSelect()
 {
     $fields = [];
     $customerAccount = $this->_fieldsetConfig->getFieldset('customer_account');
     foreach ($customerAccount as $code => $field) {
         if (isset($field['name'])) {
             $fields[$code] = $code;
         }
     }
     $connection = $this->getConnection();
     $concatenate = [];
     if (isset($fields['prefix'])) {
         $concatenate[] = $connection->getCheckSql('{{prefix}} IS NOT NULL AND {{prefix}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{prefix}}))', '\' \'']), '\'\'');
     }
     $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
     $concatenate[] = '\' \'';
     if (isset($fields['middlename'])) {
         $concatenate[] = $connection->getCheckSql('{{middlename}} IS NOT NULL AND {{middlename}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{middlename}}))', '\' \'']), '\'\'');
     }
     $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
     if (isset($fields['suffix'])) {
         $concatenate[] = $connection->getCheckSql('{{suffix}} IS NOT NULL AND {{suffix}} != \'\'', $connection->getConcatSql(['\' \'', 'LTRIM(RTRIM({{suffix}}))']), '\'\'');
     }
     $nameExpr = $connection->getConcatSql($concatenate);
     $this->addExpressionAttributeToSelect('name', $nameExpr, $fields);
     return $this;
 }
コード例 #2
0
 /**
  * @param \Magento\Customer\Model\ResourceModel\Customer\Collection $subject
  * @param \Closure $proceed
  * @return \Magento\Customer\Model\ResourceModel\Customer\Collection
  */
 public function aroundAddNameToSelect(Collection $subject, \Closure $proceed)
 {
     $fields = [];
     $customerAccount = $this->fieldsetConfig->getFieldset('customer_account');
     foreach ($customerAccount as $code => $field) {
         if (isset($field['name'])) {
             $fields[$code] = $code;
         }
     }
     $connection = $subject->getConnection();
     $concatenate = [];
     if (isset($fields['prefix'])) {
         $concatenate[] = $connection->getCheckSql('{{prefix}} IS NOT NULL AND {{prefix}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{prefix}}))', '\' \'']), '\'\'');
     }
     if ($this->localeResolver->getLocale() != 'ja_JP') {
         $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
     } else {
         $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
     }
     $concatenate[] = '\' \'';
     if (isset($fields['middlename'])) {
         $concatenate[] = $connection->getCheckSql('{{middlename}} IS NOT NULL AND {{middlename}} != \'\'', $connection->getConcatSql(['LTRIM(RTRIM({{middlename}}))', '\' \'']), '\'\'');
     }
     if ($this->localeResolver->getLocale() != 'ja_JP') {
         $concatenate[] = 'LTRIM(RTRIM({{lastname}}))';
     } else {
         $concatenate[] = 'LTRIM(RTRIM({{firstname}}))';
     }
     if (isset($fields['suffix'])) {
         $concatenate[] = $connection->getCheckSql('{{suffix}} IS NOT NULL AND {{suffix}} != \'\'', $connection->getConcatSql(['\' \'', 'LTRIM(RTRIM({{suffix}}))']), '\'\'');
     }
     $nameExpr = $connection->getConcatSql($concatenate);
     $subject->addExpressionAttributeToSelect('name', $nameExpr, $fields);
     return $subject;
 }
コード例 #3
0
ファイル: Copy.php プロジェクト: IlyaGluschenko/test001
 /**
  * Get data from object|array to object|array containing fields
  * from fieldset matching an aspect.
  *
  * @param string $fieldset
  * @param string $aspect a field name
  * @param array|\Magento\Framework\DataObject $source
  * @param string $root
  * @return array $data
  *
  * @api
  */
 public function getDataFromFieldset($fieldset, $aspect, $source, $root = 'global')
 {
     if (!(is_array($source) || $source instanceof \Magento\Framework\DataObject)) {
         return null;
     }
     $fields = $this->fieldsetConfig->getFieldset($fieldset, $root);
     if ($fields === null) {
         return null;
     }
     $data = [];
     foreach ($fields as $code => $node) {
         if (empty($node[$aspect])) {
             continue;
         }
         $value = $this->_getFieldsetFieldValue($source, $code);
         $targetCode = (string) $node[$aspect];
         $targetCode = $targetCode == '*' ? $code : $targetCode;
         $data[$targetCode] = $value;
     }
     return $data;
 }
コード例 #4
0
 public function testGetFieldsetIfFieldsetIsEmpty()
 {
     $this->_storageMock->expects($this->once())->method('get')->will($this->returnValue([]));
     $result = $this->_model->getFieldset('test');
     $this->assertEquals(null, $result);
 }