• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

PHP Reflection\DataObjectProcessor类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: testNewAccount

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testNewAccount()
 {
     $customerId = 1;
     $customerStoreId = 2;
     $customerEmail = '[email protected]';
     $customerData = ['key' => 'value'];
     $customerName = 'Customer Name';
     $templateIdentifier = 'Template Identifier';
     $sender = 'Sender';
     $customer = $this->getMock(\Magento\Customer\Api\Data\CustomerInterface::class, [], [], '', false);
     $customer->expects($this->any())->method('getStoreId')->willReturn($customerStoreId);
     $customer->expects($this->any())->method('getId')->willReturn($customerId);
     $customer->expects($this->any())->method('getEmail')->willReturn($customerEmail);
     $this->storeMock->expects($this->any())->method('getId')->willReturn($customerStoreId);
     $this->storeManagerMock->expects($this->once())->method('getStore')->with($customerStoreId)->willReturn($this->storeMock);
     $this->customerRegistryMock->expects($this->once())->method('retrieveSecureData')->with($customerId)->willReturn($this->customerSecureMock);
     $this->dataProcessorMock->expects($this->once())->method('buildOutputDataArray')->with($customer, \Magento\Customer\Api\Data\CustomerInterface::class)->willReturn($customerData);
     $this->customerViewHelperMock->expects($this->any())->method('getCustomerName')->with($customer)->willReturn($customerName);
     $this->customerSecureMock->expects($this->once())->method('addData')->with($customerData)->willReturnSelf();
     $this->customerSecureMock->expects($this->once())->method('setData')->with('name', $customerName)->willReturnSelf();
     $this->scopeConfigMock->expects($this->at(0))->method('getValue')->with(EmailNotification::XML_PATH_REGISTER_EMAIL_TEMPLATE, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($templateIdentifier);
     $this->scopeConfigMock->expects($this->at(1))->method('getValue')->with(EmailNotification::XML_PATH_REGISTER_EMAIL_IDENTITY, ScopeInterface::SCOPE_STORE, $customerStoreId)->willReturn($sender);
     $transport = $this->getMock(\Magento\Framework\Mail\TransportInterface::class, [], [], '', false);
     $this->transportBuilderMock->expects($this->once())->method('setTemplateIdentifier')->with($templateIdentifier)->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('setTemplateOptions')->with(['area' => Area::AREA_FRONTEND, 'store' => $customerStoreId])->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('setTemplateVars')->with(['customer' => $this->customerSecureMock, 'back_url' => '', 'store' => $this->storeMock])->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('setFrom')->with($sender)->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('addTo')->with($customerEmail, $customerName)->willReturnSelf();
     $this->transportBuilderMock->expects($this->once())->method('getTransport')->willReturn($transport);
     $transport->expects($this->once())->method('sendMessage');
     $this->model->newAccount($customer, EmailNotification::NEW_ACCOUNT_EMAIL_REGISTERED, '', $customerStoreId);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:35,代码来源:EmailNotificationTest.php


示例17: createSampleCustomerDataObject

 /**
  * Create customer using setters.
  *
  * @param array $additional
  * @return CustomerInterface
  */
 public function createSampleCustomerDataObject(array $additional = [])
 {
     $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 = $this->getCustomerSampleData(array_merge([CustomerData::KEY_ADDRESSES => [$address1, $address2]], $additional));
     $customer = $this->customerDataFactory->create();
     $this->dataObjectHelper->populateWithArray($customer, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     return $customer;
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:37,代码来源:Customer.php


示例18: testSaveNewAddressDefaults

 /**
  * @magentoDataFixture  Magento/Customer/_files/customer.php
  */
 public function testSaveNewAddressDefaults()
 {
     $customerId = 1;
     /** @var $addressShipping \Magento\Customer\Api\Data\AddressInterface */
     $addressShipping = $this->_expectedAddresses[0]->setId(null);
     $addressShipping->setIsDefaultShipping(true)->setIsDefaultBilling(false)->setCustomerId($customerId);
     //TODO : Will be fixed as part of fixing populate. For now Region is set as Data Object instead of array
     $addressShipping->setRegion($this->_expectedAddresses[0]->getRegion());
     /** @var $addressBilling \Magento\Customer\Api\Data\AddressInterface */
     $addressBilling = $this->_expectedAddresses[1]->setId(null);
     $addressBilling->setIsDefaultBilling(true)->setIsDefaultShipping(false)->setCustomerId($customerId);
     //TODO : Will be fixed as part of fixing populate
     $addressBilling->setRegion($this->_expectedAddresses[1]->getRegion());
     $addressShippingExpected = $this->addressRepository->save($addressShipping);
     $addressBillingExpected = $this->addressRepository->save($addressBilling);
     // Call api under test
     $shippingResponse = $this->accountManagement->getDefaultShippingAddress($customerId);
     $billingResponse = $this->accountManagement->getDefaultBillingAddress($customerId);
     // Verify if the new Shipping address created is same as returned by the api under test :
     // \Magento\Customer\Api\AccountManagementInterface::getDefaultShippingAddress
     $addressShippingExpected = $this->dataProcessor->buildOutputDataArray($addressShippingExpected, 'Magento\\Customer\\Api\\Data\\AddressInterface');
     $shippingResponse = $this->dataProcessor->buildOutputDataArray($shippingResponse, 'Magento\\Customer\\Api\\Data\\AddressInterface');
     // Response should have this set since we save as default shipping
     $addressShippingExpected[AddressInterface::DEFAULT_SHIPPING] = true;
     $this->assertEquals($addressShippingExpected, $shippingResponse);
     // Verify if the new Billing address created is same as returned by the api under test :
     // \Magento\Customer\Api\AccountManagementInterface::getDefaultShippingAddress
     $addressBillingExpected = $this->dataProcessor->buildOutputDataArray($addressBillingExpected, 'Magento\\Customer\\Api\\Data\\AddressInterface');
     $billingResponse = $this->dataProcessor->buildOutputDataArray($billingResponse, 'Magento\\Customer\\Api\\Data\\AddressInterface');
     // Response should have this set since we save as default billing
     $addressBillingExpected[AddressInterface::DEFAULT_BILLING] = true;
     $this->assertEquals($addressBillingExpected, $billingResponse);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:36,代码来源:AccountManagementTest.php


示例19: toModel

 /**
  * @param RuleDataModel $dataModel
  * @return $this|Rule
  * @throws \Magento\Framework\Exception\NoSuchEntityException
  * @throws \Magento\Framework\Exception\InputException
  */
 public function toModel(RuleDataModel $dataModel)
 {
     $ruleId = $dataModel->getRuleId();
     if ($ruleId) {
         $ruleModel = $this->ruleFactory->create()->load($ruleId);
         if (!$ruleModel->getId()) {
             throw new \Magento\Framework\Exception\NoSuchEntityException();
         }
     } else {
         $ruleModel = $this->ruleFactory->create();
     }
     $modelData = $ruleModel->getData();
     $data = $this->dataObjectProcessor->buildOutputDataArray($dataModel, '\\Magento\\SalesRule\\Api\\Data\\RuleInterface');
     $mergedData = array_merge($modelData, $data);
     $validateResult = $ruleModel->validateData(new \Magento\Framework\DataObject($mergedData));
     if ($validateResult !== true) {
         $text = '';
         /** @var \Magento\Framework\Phrase $errorMessage */
         foreach ($validateResult as $errorMessage) {
             $text .= $errorMessage->getText();
             $text .= '; ';
         }
         throw new \Magento\Framework\Exception\InputException(new \Magento\Framework\Phrase($text));
     }
     $ruleModel->setData($mergedData);
     $this->mapFields($ruleModel, $dataModel);
     return $ruleModel;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:34,代码来源:ToModel.php


示例20: testSave

该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Session\Generic类代码示例发布时间:2022-05-23
下一篇:
PHP Pricing\PriceCurrencyInterface类代码示例发布时间:2022-05-23
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap