当前位置: 首页>>代码示例>>PHP>>正文


PHP Reflection\DataObjectProcessor类代码示例

本文整理汇总了PHP中Magento\Framework\Reflection\DataObjectProcessor的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectProcessor类的具体用法?PHP DataObjectProcessor怎么用?PHP DataObjectProcessor使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了DataObjectProcessor类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 /**
  * @param string $entityType
  * @param object $entity
  * @return object
  * @throws CouldNotSaveException
  * @SuppressWarnings(PHPMD.UnusedFormalParameter)
  */
 public function execute($entityType, $entity)
 {
     /**
      * @var $entity \Magento\Catalog\Api\Data\ProductLinkInterface
      */
     $linkedProduct = $this->productRepository->get($entity->getLinkedProductSku());
     $product = $this->productRepository->get($entity->getSku());
     $links = [];
     $extensions = $this->dataObjectProcessor->buildOutputDataArray($entity->getExtensionAttributes(), 'Magento\\Catalog\\Api\\Data\\ProductLinkExtensionInterface');
     $extensions = is_array($extensions) ? $extensions : [];
     $data = $entity->__toArray();
     foreach ($extensions as $attributeCode => $attribute) {
         $data[$attributeCode] = $attribute;
     }
     unset($data['extension_attributes']);
     $data['product_id'] = $linkedProduct->getId();
     $links[$linkedProduct->getId()] = $data;
     try {
         $linkTypesToId = $this->linkTypeProvider->getLinkTypes();
         $prodyctHydrator = $this->metadataPool->getHydrator(ProductInterface::class);
         $productData = $prodyctHydrator->extract($product);
         $this->linkResource->saveProductLinks($productData[$this->metadataPool->getMetadata(ProductInterface::class)->getLinkField()], $links, $linkTypesToId[$entity->getLinkType()]);
     } catch (\Exception $exception) {
         throw new CouldNotSaveException(__('Invalid data provided for linked products'));
     }
     return $entity;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:34,代码来源:SaveHandler.php

示例2: updateData

 /**
  * Update Model with the data from Data Interface
  *
  * @param AddressInterface $address
  * @return $this
  * @deprecated Use Api/RepositoryInterface for the operations in the Data Interfaces. Don't rely on Address Model
  */
 public function updateData(AddressInterface $address)
 {
     // Set all attributes
     $attributes = $this->dataProcessor->buildOutputDataArray($address, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
     foreach ($attributes as $attributeCode => $attributeData) {
         if (AddressInterface::REGION === $attributeCode) {
             $this->setRegion($address->getRegion()->getRegion());
             $this->setRegionCode($address->getRegion()->getRegionCode());
             $this->setRegionId($address->getRegion()->getRegionId());
         } else {
             $this->setDataUsingMethod($attributeCode, $attributeData);
         }
     }
     // Need to explicitly set this due to discrepancy in the keys between model and data object
     $this->setIsDefaultBilling($address->isDefaultBilling());
     $this->setIsDefaultShipping($address->isDefaultShipping());
     if (!$this->getAttributeSetId()) {
         $this->setAttributeSetId(AddressMetadataInterface::ATTRIBUTE_SET_ID_ADDRESS);
     }
     $customAttributes = $address->getCustomAttributes();
     if ($customAttributes !== null) {
         foreach ($customAttributes as $attribute) {
             $this->setData($attribute->getAttributeCode(), $attribute->getValue());
         }
     }
     return $this;
 }
开发者ID:nja78,项目名称:magento2,代码行数:34,代码来源:Address.php

示例3: testToNestedArrayCustom

 /**
  * Test toNestedArray() method with custom attributes and with skipped custom attribute.
  */
 public function testToNestedArrayCustom()
 {
     $dataArray = ['attribute_key' => 'attribute_value', AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY => [[AttributeValue::ATTRIBUTE_CODE => 'custom_attribute_code', AttributeValue::VALUE => 'custom_attribute_value'], [AttributeValue::ATTRIBUTE_CODE => 'custom_attribute_code_multi', AttributeValue::VALUE => ['custom_attribute_value_multi_1', 'custom_attribute_value_multi_2']], [AttributeValue::ATTRIBUTE_CODE => 'custom_attribute_code_skip', AttributeValue::VALUE => 'custom_attribute_value_skip']]];
     $resultArray = ['attribute_key' => 'attribute_value', 'custom_attribute_code' => 'custom_attribute_value', 'custom_attribute_code_multi' => ['custom_attribute_value_multi_1', 'custom_attribute_value_multi_2']];
     $this->processor->expects($this->any())->method('buildOutputDataArray')->with($this->dataObject)->willReturn($dataArray);
     $this->assertEquals($resultArray, $this->converter->toNestedArray($this->dataObject, ['custom_attribute_code_skip']));
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:ExtensibleDataObjectConverterTest.php

示例4: toNestedArray

 /**
  * Convert AbstractExtensibleObject into a nested array.
  *
  * @param ExtensibleDataInterface $dataObject
  * @param string[] $skipAttributes
  * @param string $dataObjectType
  * @return array
  */
 public function toNestedArray(ExtensibleDataInterface $dataObject, $skipAttributes = [], $dataObjectType = null)
 {
     if ($dataObjectType == null) {
         $dataObjectType = get_class($dataObject);
     }
     $dataObjectArray = $this->dataObjectProcessor->buildOutputDataArray($dataObject, $dataObjectType);
     //process custom attributes if present
     if (!empty($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY])) {
         /** @var AttributeValue[] $customAttributes */
         $customAttributes = $dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY];
         unset($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY]);
         foreach ($customAttributes as $attributeValue) {
             if (!in_array($attributeValue[AttributeValue::ATTRIBUTE_CODE], $skipAttributes)) {
                 $dataObjectArray[$attributeValue[AttributeValue::ATTRIBUTE_CODE]] = $attributeValue[AttributeValue::VALUE];
             }
         }
     }
     if (!empty($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY])) {
         /** @var array $extensionAttributes */
         $extensionAttributes = $dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY];
         unset($dataObjectArray[ExtensibleDataInterface::EXTENSION_ATTRIBUTES_KEY]);
         foreach ($extensionAttributes as $attributeKey => $attributeValue) {
             if (!in_array($attributeKey, $skipAttributes)) {
                 $dataObjectArray[$attributeKey] = $attributeValue;
             }
         }
     }
     return $dataObjectArray;
 }
开发者ID:IlyaGluschenko,项目名称:protection,代码行数:37,代码来源:ExtensibleDataObjectConverter.php

示例5: executeInternal

 /**
  * Create or save customer group.
  *
  * @return \Magento\Backend\Model\View\Result\Redirect|\Magento\Backend\Model\View\Result\Forward
  */
 public function executeInternal()
 {
     $taxClass = (int) $this->getRequest()->getParam('tax_class');
     /** @var \Magento\Customer\Api\Data\GroupInterface $customerGroup */
     $customerGroup = null;
     if ($taxClass) {
         $id = $this->getRequest()->getParam('id');
         $resultRedirect = $this->resultRedirectFactory->create();
         try {
             if ($id !== null) {
                 $customerGroup = $this->groupRepository->getById((int) $id);
             } else {
                 $customerGroup = $this->groupDataFactory->create();
             }
             $customerGroupCode = (string) $this->getRequest()->getParam('code');
             if (empty($customerGroupCode)) {
                 $customerGroupCode = null;
             }
             $customerGroup->setCode($customerGroupCode);
             $customerGroup->setTaxClassId($taxClass);
             $this->groupRepository->save($customerGroup);
             $this->messageManager->addSuccess(__('You saved the customer group.'));
             $resultRedirect->setPath('customer/group');
         } catch (\Exception $e) {
             $this->messageManager->addError($e->getMessage());
             if ($customerGroup != null) {
                 $this->storeCustomerGroupDataToSession($this->dataObjectProcessor->buildOutputDataArray($customerGroup, '\\Magento\\Customer\\Api\\Data\\GroupInterface'));
             }
             $resultRedirect->setPath('customer/group/edit', ['id' => $id]);
         }
         return $resultRedirect;
     } else {
         return $this->resultForwardFactory->create()->forward('new');
     }
 }
开发者ID:nblair,项目名称:magescotch,代码行数:40,代码来源:Save.php

示例6: save

 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Customer\Api\Data\GroupInterface $group)
 {
     $this->_validate($group);
     /** @var \Magento\Customer\Model\Group $groupModel */
     $groupModel = null;
     if ($group->getId()) {
         $this->_verifyTaxClassModel($group->getTaxClassId(), $group);
         $groupModel = $this->groupRegistry->retrieve($group->getId());
         $groupDataAttributes = $this->dataObjectProcessor->buildOutputDataArray($group, '\\Magento\\Customer\\Api\\Data\\GroupInterface');
         foreach ($groupDataAttributes as $attributeCode => $attributeData) {
             $groupModel->setDataUsingMethod($attributeCode, $attributeData);
         }
     } else {
         $groupModel = $this->groupFactory->create();
         $groupModel->setCode($group->getCode());
         $taxClassId = $group->getTaxClassId() ?: self::DEFAULT_TAX_CLASS_ID;
         $this->_verifyTaxClassModel($taxClassId, $group);
         $groupModel->setTaxClassId($taxClassId);
     }
     try {
         $this->groupResourceModel->save($groupModel);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         /**
          * Would like a better way to determine this error condition but
          *  difficult to do without imposing more database calls
          */
         if ($e->getMessage() == (string) __('Customer Group already exists.')) {
             throw new InvalidTransitionException(__('Customer Group already exists.'));
         }
         throw $e;
     }
     $this->groupRegistry->remove($groupModel->getId());
     $groupDataObject = $this->groupDataFactory->create()->setId($groupModel->getId())->setCode($groupModel->getCode())->setTaxClassId($groupModel->getTaxClassId())->setTaxClassName($groupModel->getTaxClassName());
     return $groupDataObject;
 }
开发者ID:opexsw,项目名称:magento2,代码行数:38,代码来源:GroupRepository.php

示例7: extract

 /**
  * {@inheritdoc}
  */
 public function extract($entity)
 {
     $entityType = $this->typeResolver->resolve($entity);
     $data = $this->dataObjectProcessor->buildOutputDataArray($entity, $entityType);
     $mapper = $this->mapperPool->getMapper($entityType);
     return $mapper->entityToDatabase($entityType, $data);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:10,代码来源:Hydrator.php

示例8: toFlatArray

 /**
  * Convert nested array into flat array.
  *
  * @param ExtensibleDataInterface $dataObject
  * @param string $dataObjectType
  * @return array
  */
 public function toFlatArray(ExtensibleDataInterface $dataObject, $dataObjectType = null)
 {
     if ($dataObjectType === null) {
         $dataObjectType = get_class($dataObject);
     }
     $data = $this->dataObjectProcessor->buildOutputDataArray($dataObject, $dataObjectType);
     return ConvertArray::toFlatArray($data);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:15,代码来源:SimpleDataObjectConverter.php

示例9: save

 /**
  * {@inheritdoc}
  */
 public function save(\Stepzerosolutions\Tbslider\Api\Data\SlideritemsInterface $slider)
 {
     $this->_validate($slider);
     /** @var \Stepzerosolutions\Tbslider\Model\Bookings\Slideritems $sliderModel */
     $sliderModel = null;
     if ($slider->getId()) {
         $sliderModel = $this->slideritemsRegistry->retrieve($slider->getId());
         $sliderDataAttributes = $this->dataObjectProcessor->buildOutputDataArray($slider, '\\Stepzerosolutions\\Tbslider\\Api\\Data\\SlideritemsInterface');
         foreach ($sliderDataAttributes as $attributeCode => $attributeData) {
             $sliderModel->setDataUsingMethod($attributeCode, $attributeData);
         }
     } else {
         $sliderModel = $this->slideritemsFactory->create();
         $sliderModel->setSlideritemTitle($slider->getSlideritemTitle());
         $sliderModel->setSlideritem_description($slider->getSlideritemDescription());
         $sliderModel->setSlideritemSlider($slider->getSlideritemSlider());
         $sliderModel->setSliderImagePath($slider->getSliderImagePath());
         $sliderModel->setSliderImageMdPath($slider->getSliderImageMdPath());
         $sliderModel->setSliderImageSmPath($slider->getSliderImageSmPath());
         $sliderModel->setSliderImageXsPath($slider->getSliderImageXsPath());
         $sliderModel->setSliderUrl($slider->getSliderUrl());
         $sliderModel->setDate($slider->getDate());
         $sliderModel->setTimestamp($slider->getTimestamp());
         $sliderModel->setSliderSort($slider->getSliderSort());
         $sliderModel->setCaptionmeta($slider->getCaptionmeta());
         $sliderModel->setIsActive($slider->getIsActive());
     }
     try {
         $this->slideritemsResourceModel->save($sliderModel);
     } catch (\Magento\Framework\Exception\LocalizedException $e) {
         /**
          * Would like a better way to determine this error condition but
          *  difficult to do without imposing more database calls
          */
         die($e->getMessage());
         if ($e->getMessage() == (string) __('Slideritems already exists.')) {
             throw new InvalidTransitionException(__('Slideritems already exists.'));
         }
         throw $e;
     }
     $this->slideritemsRegistry->remove($sliderModel->getId());
     $sliderDataObject = $this->slideritemsDataFactory->create();
     $sliderDataObject->setSlideritemTitle($sliderModel->getSlideritemTitle());
     $sliderDataObject->setSlideritemDescription($sliderModel->getSlideritemDescription());
     $sliderDataObject->setSlideritemSlider($sliderModel->getSlideritemSlider());
     $sliderDataObject->setSliderImagePath($sliderModel->getSliderImagePath());
     $sliderDataObject->setSliderImageMdPath($sliderModel->getSliderImageMdPath());
     $sliderDataObject->setSliderImageSmPath($sliderModel->getSliderImageSmPath());
     $sliderDataObject->setSliderImageXsPath($sliderModel->getSliderImageXsPath());
     $sliderDataObject->setSliderUrl($sliderModel->getSliderUrl());
     $sliderDataObject->setDate($sliderModel->getDate());
     $sliderDataObject->setTimestamp($sliderModel->getTimestamp());
     $sliderDataObject->setSliderSort($sliderModel->getSliderSort());
     $sliderDataObject->setCaptionmeta($sliderModel->getCaptionmeta());
     $sliderDataObject->setIsActive($sliderModel->getIsActive());
     return $sliderDataObject;
 }
开发者ID:stepzerosolutions,项目名称:tbslider,代码行数:60,代码来源:ItemsRepository.php

示例10: getList

 /**
  * Retrieve slides matching the specified criteria.
  *
  * @param \Magento\Framework\Api\SearchCriteriaInterface $searchCriteria
  * @return \Magento\Framework\Api\SearchResultsInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $searchCriteria)
 {
     $this->searchResultsFactory->setSearchCriteria($searchCriteria);
     $collection = $this->slideCollectionFactory->create();
     foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
         foreach ($filterGroup->getFilters() as $filter) {
             $condition = $filter->getConditionType() ?: 'eq';
             $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
         }
     }
     $this->searchResultsFactory->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), strtoupper($sortOrder->getDirection()) === 'ASC' ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $slides = [];
     /** @var \Foggyline\Slider\Model\Slide $slideModel */
     foreach ($collection as $slideModel) {
         $slideData = $this->dataSlideFactory->create();
         $this->dataObjectHelper->populateWithArray($slideData, $slideModel->getData(), '\\Foggyline\\Slider\\Api\\Data\\SlideInterface');
         $slides[] = $this->dataObjectProcessor->buildOutputDataArray($slideData, '\\Foggyline\\Slider\\Api\\Data\\SlideInterface');
     }
     $this->searchResultsFactory->setItems($slides);
     return $this->searchResultsFactory;
 }
开发者ID:ksz2013,项目名称:B05032-Foggyline_Slider,代码行数:36,代码来源:SlideRepository.php

示例11: getList

 /**
  * Retrieve log entities matching the specified criteria.
  *
  * @param \Magento\Framework\Api\SearchCriteriaInterface $criteria
  * @return \Foggyline\Sentinel\Api\Data\LoginLogSearchResultsInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $criteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($criteria);
     /* @var $collection \Foggyline\Sentinel\Model\ResourceModel\LoginLog\Collection */
     $collection = $this->logCollectionFactory->create();
     foreach ($criteria->getFilterGroups() as $filterGroup) {
         foreach ($filterGroup->getFilters() as $filter) {
             if ($filter->getField() === 'store_id') {
                 $collection->addFieldToFilter('store', ['in' => $filter->getValue()]);
                 continue;
             }
             $condition = $filter->getConditionType() ?: 'eq';
             $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
         }
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $criteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($criteria->getCurrentPage());
     $collection->setPageSize($criteria->getPageSize());
     $logs = [];
     /** @var \Foggyline\Sentinel\Model\LoginLog $logModel */
     foreach ($collection as $logModel) {
         $logData = $this->dataLoginLogFactory->create();
         $this->dataObjectHelper->populateWithArray($logData, $logModel->getData(), '\\Foggyline\\Sentinel\\Api\\Data\\LoginLogInterface');
         $logs[] = $this->dataObjectProcessor->buildOutputDataArray($logData, '\\Foggyline\\Sentinel\\Api\\Data\\LoginLogInterface');
     }
     $searchResults->setItems($logs);
     return $searchResults;
 }
开发者ID:ajzele,项目名称:Foggyline_Sentinel,代码行数:42,代码来源:LoginLogRepository.php

示例12: createSampleCustomerDataObject

 /**
  * Create customer using setters.
  *
  * @return CustomerInterface
  */
 public function createSampleCustomerDataObject()
 {
     $customerAddress1 = $this->customerAddressFactory->create();
     $customerAddress1->setCountryId('US');
     $customerAddress1->setIsDefaultBilling(true);
     $customerAddress1->setIsDefaultShipping(true);
     $customerAddress1->setPostcode('75477');
     $customerAddress1->setRegion(Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\RegionInterfaceFactory')->create()->setRegionCode(self::ADDRESS_REGION_CODE1)->setRegion('Alabama')->setRegionId(1));
     $customerAddress1->setStreet(['Green str, 67']);
     $customerAddress1->setTelephone('3468676');
     $customerAddress1->setCity(self::ADDRESS_CITY1);
     $customerAddress1->setFirstname('John');
     $customerAddress1->setLastname('Smith');
     $address1 = $this->dataObjectProcessor->buildOutputDataArray($customerAddress1, 'Magento\\Customer\\Api\\Data\\AddressInterface');
     $customerAddress2 = $this->customerAddressFactory->create();
     $customerAddress2->setCountryId('US');
     $customerAddress2->setIsDefaultBilling(false);
     $customerAddress2->setIsDefaultShipping(false);
     $customerAddress2->setPostcode('47676');
     $customerAddress2->setRegion(Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\RegionInterfaceFactory')->create()->setRegionCode(self::ADDRESS_REGION_CODE2)->setRegion('Alabama')->setRegionId(1));
     $customerAddress2->setStreet(['Black str, 48', 'Building D']);
     $customerAddress2->setTelephone('3234676');
     $customerAddress2->setCity(self::ADDRESS_CITY2);
     $customerAddress2->setFirstname('John');
     $customerAddress2->setLastname('Smith');
     $address2 = $this->dataObjectProcessor->buildOutputDataArray($customerAddress2, 'Magento\\Customer\\Api\\Data\\AddressInterface');
     $customerData = [CustomerData::FIRSTNAME => self::FIRSTNAME, CustomerData::LASTNAME => self::LASTNAME, CustomerData::EMAIL => 'janedoe' . uniqid() . '@example.com', CustomerData::CONFIRMATION => self::CONFIRMATION, CustomerData::CREATED_AT => self::CREATED_AT, CustomerData::CREATED_IN => self::STORE_NAME, CustomerData::DOB => self::DOB, CustomerData::GENDER => self::GENDER, CustomerData::GROUP_ID => self::GROUP_ID, CustomerData::MIDDLENAME => self::MIDDLENAME, CustomerData::PREFIX => self::PREFIX, CustomerData::STORE_ID => self::STORE_ID, CustomerData::SUFFIX => self::SUFFIX, CustomerData::TAXVAT => self::TAXVAT, CustomerData::WEBSITE_ID => self::WEBSITE_ID, CustomerData::KEY_ADDRESSES => [$address1, $address2], 'custom_attributes' => [['attribute_code' => 'disable_auto_group_change', 'value' => '0']]];
     $customer = $this->customerDataFactory->create();
     $this->dataObjectHelper->populateWithArray($customer, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     return $customer;
 }
开发者ID:andrewhowdencom,项目名称:m2onk8s,代码行数:36,代码来源:Customer.php

示例13: getList

 /**
  * Load Page data collection by given search criteria
  *
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @param \Magento\Framework\Api\SearchCriteriaInterface $criteria
  * @return \Magento\Cms\Model\ResourceModel\Page\Collection
  */
 public function getList(\Magento\Framework\Api\SearchCriteriaInterface $criteria)
 {
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($criteria);
     $collection = $this->pageCollectionFactory->create();
     foreach ($criteria->getFilterGroups() as $filterGroup) {
         foreach ($filterGroup->getFilters() as $filter) {
             if ($filter->getField() === 'store_id') {
                 $collection->addStoreFilter($filter->getValue(), false);
                 continue;
             }
             $condition = $filter->getConditionType() ?: 'eq';
             $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
         }
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $criteria->getSortOrders();
     if ($sortOrders) {
         /** @var SortOrder $sortOrder */
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($criteria->getCurrentPage());
     $collection->setPageSize($criteria->getPageSize());
     $pages = [];
     /** @var Page $pageModel */
     foreach ($collection as $pageModel) {
         $pageData = $this->dataPageFactory->create();
         $this->dataObjectHelper->populateWithArray($pageData, $pageModel->getData(), 'Magento\\Cms\\Api\\Data\\PageInterface');
         $pages[] = $this->dataObjectProcessor->buildOutputDataArray($pageData, 'Magento\\Cms\\Api\\Data\\PageInterface');
     }
     $searchResults->setItems($pages);
     return $searchResults;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:43,代码来源:PageRepository.php

示例14: convertValue

 /**
  * Convert associative array into proper data object.
  *
  * @param array $data
  * @param string $dataType
  * @return array|object
  */
 public function convertValue($data, $dataType)
 {
     if (is_array($data)) {
         $result = [];
         $arrayElementType = substr($dataType, 0, -2);
         foreach ($data as $datum) {
             if (is_object($datum)) {
                 $datum = $this->processDataObject(
                     $this->dataObjectProcessor->buildOutputDataArray($datum, $arrayElementType)
                 );
             }
             $result[] = $datum;
         }
         return $result;
     } elseif (is_object($data)) {
         return $this->processDataObject(
             $this->dataObjectProcessor->buildOutputDataArray($data, $dataType)
         );
     } elseif ($data === null) {
         return [];
     } else {
         /** No processing is required for scalar types */
         return $data;
     }
 }
开发者ID:vasiljok,项目名称:magento2,代码行数:32,代码来源:ServiceOutputProcessor.php

示例15: getList

 /**
  * Retrieve teaserItems matching the specified criteria.
  *
  * @param SearchCriteriaInterface $searchCriteria
  *
  * @return Data\TeaserItemSearchResultInterface
  *
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     /** @var Data\TeaserItemSearchResultInterface $searchResults */
     $searchResults = $this->searchResultsFactory->create();
     $searchResults->setSearchCriteria($searchCriteria);
     /** @var TeaserItemResource\Collection $collection */
     $collection = $this->teaserItemCollectionFactory->create();
     foreach ($searchCriteria->getFilterGroups() as $filterGroup) {
         foreach ($filterGroup->getFilters() as $filter) {
             $condition = $filter->getConditionType() ?: 'eq';
             $collection->addFieldToFilter($filter->getField(), [$condition => $filter->getValue()]);
         }
     }
     $searchResults->setTotalCount($collection->getSize());
     $sortOrders = $searchCriteria->getSortOrders();
     if ($sortOrders) {
         foreach ($sortOrders as $sortOrder) {
             $collection->addOrder($sortOrder->getField(), $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
         }
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     $teaserItems = [];
     /** @var TeaserItem $teaserItemModel */
     foreach ($collection as $teaserItemModel) {
         $teaserItemData = $this->teaserItemFactory->create();
         $this->dataObjectHelper->populateWithArray($teaserItemData, $teaserItemModel->getData(), Data\TeaserItemInterface::class);
         $teaserItems[] = $this->dataObjectProcessor->buildOutputDataArray($teaserItemData, Data\TeaserItemInterface::class);
     }
     $searchResults->setItems($teaserItems);
     return $searchResults;
 }
开发者ID:davidverholen,项目名称:magento2-teaser,代码行数:41,代码来源:TeaserItemRepository.php


注:本文中的Magento\Framework\Reflection\DataObjectProcessor类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。