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


PHP Api\DataObjectHelper类代码示例

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


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

示例1: setUp

 public function setUp()
 {
     if (!function_exists('libxml_set_external_entity_loader')) {
         $this->markTestSkipped('Skipped on HHVM. Will be fixed in MAGETWO-45033');
     }
     $this->customer = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\CustomerInterface', [], '', false, true, true);
     $this->customer->expects($this->once())->method('getWebsiteId')->willReturn(2);
     $this->customerDataFactory = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['create'], [], '', false);
     $this->customerDataFactory->expects($this->once())->method('create')->willReturn($this->customer);
     $this->form = $this->getMock('Magento\\Customer\\Model\\Metadata\\Form', [], [], '', false);
     $this->request = $this->getMockForAbstractClass('Magento\\Framework\\App\\RequestInterface', [], '', false, true, true, ['getPost']);
     $this->response = $this->getMockForAbstractClass('Magento\\Framework\\App\\ResponseInterface', [], '', false);
     $this->formFactory = $this->getMock('Magento\\Customer\\Model\\Metadata\\FormFactory', ['create'], [], '', false);
     $this->formFactory->expects($this->atLeastOnce())->method('create')->willReturn($this->form);
     $this->extensibleDataObjectConverter = $this->getMock('Magento\\Framework\\Api\\ExtensibleDataObjectConverter', [], [], '', false);
     $this->dataObjectHelper = $this->getMock('Magento\\Framework\\Api\\DataObjectHelper', [], [], '', false);
     $this->dataObjectHelper->expects($this->once())->method('populateWithArray');
     $this->customerAccountManagement = $this->getMockForAbstractClass('Magento\\Customer\\Api\\AccountManagementInterface', [], '', false, true, true);
     $this->resultJson = $this->getMock('Magento\\Framework\\Controller\\Result\\Json', [], [], '', false);
     $this->resultJson->expects($this->once())->method('setData');
     $this->resultJsonFactory = $this->getMock('Magento\\Framework\\Controller\\Result\\JsonFactory', ['create'], [], '', false);
     $this->resultJsonFactory->expects($this->once())->method('create')->willReturn($this->resultJson);
     $objectHelper = new \Magento\Framework\TestFramework\Unit\Helper\ObjectManager($this);
     $this->controller = $objectHelper->getObject('Magento\\Customer\\Controller\\Adminhtml\\Index\\Validate', ['request' => $this->request, 'response' => $this->response, 'customerDataFactory' => $this->customerDataFactory, 'formFactory' => $this->formFactory, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverter, 'customerAccountManagement' => $this->customerAccountManagement, 'resultJsonFactory' => $this->resultJsonFactory, 'dataObjectHelper' => $this->dataObjectHelper]);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:25,代码来源:ValidateTest.php

示例2: execute

 /**
  * @return \Magento\Customer\Api\Data\AddressInterface|string
  */
 public function execute()
 {
     $customerAddressData = $this->getRequest()->getParam('address');
     $customerAddressDataWithRegion = [];
     $customerAddressDataWithRegion['region']['region'] = $customerAddressData['region'];
     if (isset($customerAddressData['region_code'])) {
         $customerAddressDataWithRegion['region']['region_code'] = $customerAddressData['region_code'];
     }
     if ($customerAddressData['region_id']) {
         $customerAddressDataWithRegion['region']['region_id'] = $customerAddressData['region_id'];
     }
     $customerAddressData = array_merge($customerAddressData, $customerAddressDataWithRegion);
     /**
      * @var \Magento\Customer\Api\Data\AddressInterface $addressDataObject
      */
     $addressDataObject = $this->customerAddressFactory->create();
     $this->dataObjectHelper->populateWithArray($addressDataObject, $customerAddressData, '\\Magento\\Customer\\Api\\Data\\AddressInterface');
     $addressValidationResponse = $this->validAddressManagement->saveValidAddress($addressDataObject, \Magento\Store\Model\Store::DEFAULT_STORE_ID);
     $resultJson = $this->resultJsonFactory->create();
     if (!is_string($addressValidationResponse)) {
         $resultJson->setData([AddressInterface::FIRSTNAME => $addressValidationResponse->getFirstname(), AddressInterface::LASTNAME => $addressValidationResponse->getLastname(), AddressInterface::STREET => $addressValidationResponse->getStreet(), AddressInterface::COUNTRY_ID => $addressValidationResponse->getCountryId(), AddressInterface::CITY => $addressValidationResponse->getCity(), AddressInterface::REGION_ID => $addressValidationResponse->getRegionId(), AddressInterface::REGION => $addressValidationResponse->getRegion(), AddressInterface::POSTCODE => $addressValidationResponse->getPostcode()]);
     } else {
         $resultJson->setData($addressValidationResponse);
     }
     return $resultJson;
 }
开发者ID:classyllama,项目名称:ClassyLlama_AvaTax,代码行数:29,代码来源:Validation.php

示例3: save

 /**
  * {@inheritdoc}
  */
 public function save(CustomAttributesDataInterface $dataObjectWithCustomAttributes, $entityType, CustomAttributesDataInterface $previousCustomerData = null)
 {
     //Get all Image related custom attributes
     $imageDataObjects = $this->dataObjectHelper->getCustomAttributeValueByType($dataObjectWithCustomAttributes->getCustomAttributes(), '\\Magento\\Framework\\Api\\Data\\ImageContentInterface');
     // Return if no images to process
     if (empty($imageDataObjects)) {
         return $dataObjectWithCustomAttributes;
     }
     // For every image, save it and replace it with corresponding Eav data object
     /** @var $imageDataObject \Magento\Framework\Api\AttributeValue */
     foreach ($imageDataObjects as $imageDataObject) {
         /** @var $imageContent \Magento\Framework\Api\Data\ImageContentInterface */
         $imageContent = $imageDataObject->getValue();
         $filename = $this->processImageContent($entityType, $imageContent);
         //Set filename from static media location into data object
         $dataObjectWithCustomAttributes->setCustomAttribute($imageDataObject->getAttributeCode(), $filename);
         //Delete previously saved image if it exists
         if ($previousCustomerData) {
             $previousImageAttribute = $previousCustomerData->getCustomAttribute($imageDataObject->getAttributeCode());
             if ($previousImageAttribute) {
                 $previousImagePath = $previousImageAttribute->getValue();
                 if (!empty($previousImagePath)) {
                     @unlink($this->mediaDirectory->getAbsolutePath() . $entityType . $previousImagePath);
                 }
             }
         }
     }
     return $dataObjectWithCustomAttributes;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:32,代码来源:ImageProcessor.php

示例4: createMetadataAttribute

 /**
  * Create AttributeMetadata Data object from the Attribute Model
  *
  * @param \Magento\Customer\Model\Attribute $attribute
  * @return \Magento\Customer\Api\Data\AttributeMetadataInterface
  */
 public function createMetadataAttribute($attribute)
 {
     $options = [];
     if ($attribute->usesSource()) {
         foreach ($attribute->getSource()->getAllOptions() as $option) {
             $optionDataObject = $this->optionFactory->create();
             if (!is_array($option['value'])) {
                 $optionDataObject->setValue($option['value']);
             } else {
                 $optionArray = [];
                 foreach ($option['value'] as $optionArrayValues) {
                     $optionObject = $this->optionFactory->create();
                     $this->dataObjectHelper->populateWithArray($optionObject, $optionArrayValues, '\\Magento\\Customer\\Api\\Data\\OptionInterface');
                     $optionArray[] = $optionObject;
                 }
                 $optionDataObject->setOptions($optionArray);
             }
             $optionDataObject->setLabel($option['label']);
             $options[] = $optionDataObject;
         }
     }
     $validationRules = [];
     foreach ($attribute->getValidateRules() as $name => $value) {
         $validationRule = $this->validationRuleFactory->create()->setName($name)->setValue($value);
         $validationRules[] = $validationRule;
     }
     return $this->attributeMetadataFactory->create()->setAttributeCode($attribute->getAttributeCode())->setFrontendInput($attribute->getFrontendInput())->setInputFilter((string) $attribute->getInputFilter())->setStoreLabel($attribute->getStoreLabel())->setValidationRules($validationRules)->setIsVisible((bool) $attribute->getIsVisible())->setIsRequired((bool) $attribute->getIsRequired())->setMultilineCount((int) $attribute->getMultilineCount())->setDataModel((string) $attribute->getDataModel())->setOptions($options)->setFrontendClass($attribute->getFrontend()->getClass())->setFrontendLabel($attribute->getFrontendLabel())->setNote((string) $attribute->getNote())->setIsSystem((bool) $attribute->getIsSystem())->setIsUserDefined((bool) $attribute->getIsUserDefined())->setBackendType($attribute->getBackendType())->setSortOrder((int) $attribute->getSortOrder())->setIsUsedInGrid($attribute->getIsUsedInGrid())->setIsVisibleInGrid($attribute->getIsVisibleInGrid())->setIsFilterableInGrid($attribute->getIsFilterableInGrid())->setIsSearchableInGrid($attribute->getIsSearchableInGrid());
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:34,代码来源:AttributeMetadataConverter.php

示例5: prepareQuoteForNewCustomer

 /**
  * @param \Magento\Quote\Model\Quote $quote
  * @return \Magento\Quote\Model\Quote
  */
 public function prepareQuoteForNewCustomer(\Magento\Quote\Model\Quote $quote)
 {
     $billing = $quote->getBillingAddress();
     $shipping = $quote->isVirtual() ? null : $quote->getShippingAddress();
     $billing->setDefaultBilling(true);
     if ($shipping && !$shipping->getSameAsBilling()) {
         $shipping->setDefaultShipping(true);
         $address = $shipping->exportCustomerAddress();
         $shipping->setCustomerAddressData($address);
     } elseif ($shipping) {
         $billing->setDefaultShipping(true);
     }
     $address = $shipping->exportCustomerAddress();
     $billing->setCustomerAddressData($address);
     foreach (['customer_dob', 'customer_taxvat', 'customer_gender'] as $attribute) {
         if ($quote->getData($attribute) && !$billing->getData($attribute)) {
             $billing->setData($attribute, $quote->getData($attribute));
         }
     }
     $customer = $this->customerFactory->create();
     $this->dataObjectHelper->populateWithArray($customer, $this->copyObject->getDataFromFieldset('checkout_onepage_billing', 'to_customer', $billing), '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $customer->setEmail($quote->getCustomerEmail());
     $customer->setPrefix($quote->getCustomerPrefix());
     $customer->setFirstname($quote->getCustomerFirstname());
     $customer->setMiddlename($quote->getCustomerMiddlename());
     $customer->setLastname($quote->getCustomerLastname());
     $customer->setSuffix($quote->getCustomerSuffix());
     $quote->setCustomer($customer);
     $quote->addCustomerAddress($billing->exportCustomerAddress());
     if ($shipping->hasCustomerAddress()) {
         $quote->addCustomerAddress($shipping->exportCustomerAddress());
     }
     return $quote;
 }
开发者ID:nja78,项目名称:magento2,代码行数:38,代码来源:Quote.php

示例6: testGetChildren

 public function testGetChildren()
 {
     $productId = 'test';
     $product = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $productTypeInstance = $this->getMockBuilder('Magento\\ConfigurableProduct\\Model\\Product\\Type\\Configurable')->disableOriginalConstructor()->getMock();
     $product->expects($this->any())->method('getTypeId')->willReturn(Configurable::TYPE_CODE);
     $product->expects($this->any())->method('getStoreId')->willReturn(1);
     $product->expects($this->any())->method('getTypeInstance')->willReturn($productTypeInstance);
     $productTypeInstance->expects($this->once())->method('setStoreFilter')->with(1, $product);
     $childProduct = $this->getMockBuilder('Magento\\Catalog\\Model\\Product')->disableOriginalConstructor()->getMock();
     $productTypeInstance->expects($this->any())->method('getUsedProducts')->with($product)->willReturn([$childProduct]);
     $this->productRepository->expects($this->any())->method('get')->with($productId)->willReturn($product);
     $attribute = $this->getMock('\\Magento\\Eav\\Api\\Data\\AttributeInterface');
     $attribute->expects($this->once())->method('getAttributeCode')->willReturn('code');
     $childProduct->expects($this->once())->method('getDataUsingMethod')->with('code')->willReturn(false);
     $childProduct->expects($this->once())->method('getData')->with('code')->willReturn(10);
     $childProduct->expects($this->once())->method('getStoreId')->willReturn(1);
     $childProduct->expects($this->once())->method('getAttributes')->willReturn([$attribute]);
     $productMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductInterface');
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray')->with($productMock, ['store_id' => 1, 'code' => 10], '\\Magento\\Catalog\\Api\\Data\\ProductInterface')->willReturnSelf();
     $this->productFactory->expects($this->once())->method('create')->willReturn($productMock);
     $products = $this->object->getChildren($productId);
     $this->assertCount(1, $products);
     $this->assertEquals($productMock, $products[0]);
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:25,代码来源:LinkManagementTest.php

示例7: convert

    /**
     * @param Address $object
     * @param array $data
     * @return OrderInterface
     */
    public function convert(Address $object, $data = [])
    {
        $orderData = $this->objectCopyService->getDataFromFieldset(
            'quote_convert_address',
            'to_order',
            $object
        );
        /**
         * @var $order \Magento\Sales\Model\Order
         */
        $order = $this->orderFactory->create();
        $this->dataObjectHelper->populateWithArray(
            $order,
            array_merge($orderData, $data),
            '\Magento\Sales\Api\Data\OrderInterface'
        );
        $order->setStoreId($object->getQuote()->getStoreId())
            ->setQuoteId($object->getQuote()->getId())
            ->setIncrementId($object->getQuote()->getReservedOrderId());
        $this->objectCopyService->copyFieldsetToTarget('sales_convert_quote', 'to_order', $object->getQuote(), $order);
        $this->eventManager->dispatch(
            'sales_convert_quote_to_order',
            ['order' => $order, 'quote' => $object->getQuote()]
        );
        return $order;

    }
开发者ID:razbakov,项目名称:magento2,代码行数:32,代码来源:ToOrder.php

示例8: get

 /**
  * {@inheritDoc}
  *
  * @param int $cartId The cart ID.
  * @return Totals Quote totals data.
  */
 public function get($cartId)
 {
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = $this->quoteRepository->getActive($cartId);
     if ($quote->isVirtual()) {
         $addressTotalsData = $quote->getBillingAddress()->getData();
         $addressTotals = $quote->getBillingAddress()->getTotals();
     } else {
         $addressTotalsData = $quote->getShippingAddress()->getData();
         $addressTotals = $quote->getShippingAddress()->getTotals();
     }
     /** @var \Magento\Quote\Api\Data\TotalsInterface $quoteTotals */
     $quoteTotals = $this->totalsFactory->create();
     $this->dataObjectHelper->populateWithArray($quoteTotals, $addressTotalsData, '\\Magento\\Quote\\Api\\Data\\TotalsInterface');
     $items = [];
     foreach ($quote->getAllVisibleItems() as $index => $item) {
         $items[$index] = $this->itemConverter->modelToDataObject($item);
     }
     $calculatedTotals = $this->totalsConverter->process($addressTotals);
     $quoteTotals->setTotalSegments($calculatedTotals);
     $amount = $quoteTotals->getGrandTotal() - $quoteTotals->getTaxAmount();
     $amount = $amount > 0 ? $amount : 0;
     $quoteTotals->setCouponCode($this->couponService->get($cartId));
     $quoteTotals->setGrandTotal($amount);
     $quoteTotals->setItems($items);
     $quoteTotals->setItemsQty($quote->getItemsQty());
     $quoteTotals->setBaseCurrencyCode($quote->getBaseCurrencyCode());
     $quoteTotals->setQuoteCurrencyCode($quote->getQuoteCurrencyCode());
     return $quoteTotals;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:36,代码来源:CartTotalRepository.php

示例9: convert

 /**
  * @param Address $object
  * @param array $data
  * @return OrderAddressInterface
  */
 public function convert(Address $object, $data = [])
 {
     $orderAddress = $this->orderAddressRepository->create();
     $orderAddressData = $this->objectCopyService->getDataFromFieldset('quote_convert_address', 'to_order_address', $object);
     $this->dataObjectHelper->populateWithArray($orderAddress, array_merge($orderAddressData, $data), '\\Magento\\Sales\\Api\\Data\\OrderAddressInterface');
     return $orderAddress;
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:12,代码来源:ToOrderAddress.php

示例10: getChildren

 /**
  * {@inheritdoc}
  */
 public function getChildren($sku)
 {
     /** @var \Magento\Catalog\Model\Product $product */
     $product = $this->productRepository->get($sku);
     if ($product->getTypeId() != \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE) {
         return [];
     }
     /** @var \Magento\ConfigurableProduct\Model\Product\Type\Configurable $productTypeInstance */
     $productTypeInstance = $product->getTypeInstance();
     $productTypeInstance->setStoreFilter($product->getStoreId(), $product);
     $childrenList = [];
     /** @var \Magento\Catalog\Model\Product $child */
     foreach ($productTypeInstance->getUsedProducts($product) as $child) {
         $attributes = [];
         foreach ($child->getAttributes() as $attribute) {
             $attrCode = $attribute->getAttributeCode();
             $value = $child->getDataUsingMethod($attrCode) ?: $child->getData($attrCode);
             if (null !== $value && $attrCode != 'entity_id') {
                 $attributes[$attrCode] = $value;
             }
         }
         $attributes['store_id'] = $child->getStoreId();
         /** @var \Magento\Catalog\Api\Data\ProductInterface $productDataObject */
         $productDataObject = $this->productFactory->create();
         $this->dataObjectHelper->populateWithArray($productDataObject, $attributes, '\\Magento\\Catalog\\Api\\Data\\ProductInterface');
         $childrenList[] = $productDataObject;
     }
     return $childrenList;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:32,代码来源:LinkManagement.php

示例11: hydrate

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

示例12: modelToDataObject

 /**
  * Converts a specified rate model to a shipping method data object.
  *
  * @param \Magento\Quote\Model\Quote\Item $item
  * @return array
  * @throws \Exception
  */
 public function modelToDataObject($item)
 {
     $this->eventManager->dispatch('items_additional_data', ['item' => $item]);
     $items = $item->toArray();
     $items['options'] = $this->getFormattedOptionValue($item);
     $itemsData = $this->totalsItemFactory->create();
     $this->dataObjectHelper->populateWithArray($itemsData, $items, '\\Magento\\Quote\\Api\\Data\\TotalsItemInterface');
     return $itemsData;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:ItemConverter.php

示例13: testFindOneByDataIfFound

 public function testFindOneByDataIfFound()
 {
     $data = [['field1' => 'value1']];
     $row = ['row1'];
     $urlRewrite = ['urlRewrite1'];
     $this->storage->expects($this->once())->method('doFindOneByData')->with($data)->will($this->returnValue($row));
     $this->dataObjectHelper->expects($this->once())->method('populateWithArray')->with($urlRewrite, $row, '\\Magento\\UrlRewrite\\Service\\V1\\Data\\UrlRewrite')->will($this->returnSelf());
     $this->urlRewriteFactory->expects($this->any())->method('create')->will($this->returnValue($urlRewrite));
     $this->assertEquals($urlRewrite, $this->storage->findOneByData($data));
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:10,代码来源:AbstractStorageTest.php

示例14: testGetItems

 public function testGetItems()
 {
     $inputTypeMock = $this->getMock('Magento\\Catalog\\Model\\Product\\Attribute\\Source\\Inputtype', [], [], '', false);
     $this->inputTypeFactoryMock->expects($this->once())->method('create')->willReturn($inputTypeMock);
     $inputTypeMock->expects($this->once())->method('toOptionArray')->willReturn(['option' => ['value']]);
     $attributeTypeMock = $this->getMock('\\Magento\\Catalog\\Api\\Data\\ProductAttributeTypeInterface');
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray')->with($attributeTypeMock, ['value'], '\\Magento\\Catalog\\Api\\Data\\ProductAttributeTypeInterface')->willReturnSelf();
     $this->attributeTypeFactoryMock->expects($this->once())->method('create')->willReturn($attributeTypeMock);
     $this->assertEquals([$attributeTypeMock], $this->model->getItems());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:10,代码来源:TypesListTest.php

示例15: convertToProductOption

 /**
  * {@inheritdoc}
  */
 public function convertToProductOption(DataObject $request)
 {
     /** @var DownloadableOption $downloadableOption */
     $downloadableOption = $this->downloadableOptionFactory->create();
     $links = $request->getLinks();
     if (!empty($links) && is_array($links)) {
         $this->dataObjectHelper->populateWithArray($downloadableOption, ['downloadable_links' => $links], 'Magento\\Downloadable\\Api\\Data\\DownloadableOptionInterface');
         return ['downloadable_option' => $downloadableOption];
     }
     return [];
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:14,代码来源:ProductOptionProcessor.php


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