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

PHP Api\ExtensibleDataObjectConverter类代码示例

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

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



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

示例1: setUp

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 protected function setUp()
 {
     $this->addressRepositoryMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\AddressRepositoryInterface', ['get'], '', false);
     $this->accountManagementMock = $this->getMockForAbstractClass('Magento\\Customer\\Api\\AccountManagementInterface', [], '', false);
     $this->eventManagerMock = $this->getMock('Magento\\Framework\\Event\\ManagerInterface');
     $this->checkoutHelperMock = $this->getMock('Magento\\Checkout\\Helper\\Data', [], [], '', false);
     $this->customerUrlMock = $this->getMock('Magento\\Customer\\Model\\Url', [], [], '', false);
     $this->loggerMock = $this->getMock('Psr\\Log\\LoggerInterface');
     $this->checkoutSessionMock = $this->getMock('Magento\\Checkout\\Model\\Session', ['getLastOrderId', 'getQuote', 'setStepData', 'getStepData'], [], '', false);
     $this->customerSessionMock = $this->getMock('Magento\\Customer\\Model\\Session', ['getCustomerDataObject', 'isLoggedIn'], [], '', false);
     $this->storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManagerInterface');
     $this->requestMock = $this->getMockBuilder('Magento\\Framework\\App\\Request\\Http')->disableOriginalConstructor()->getMock();
     $this->addressFactoryMock = $this->getMock('Magento\\Customer\\Model\\AddressFactory', [], [], '', false);
     $this->formFactoryMock = $this->getMock('Magento\\Customer\\Model\\Metadata\\FormFactory', [], [], '', false);
     $this->customerFactoryMock = $this->getMock('Magento\\Customer\\Model\\CustomerFactory', [], [], '', false);
     $this->quoteManagementMock = $this->getMock('Magento\\Quote\\Model\\QuoteManagement', [], [], '', false);
     $this->orderFactoryMock = $this->getMock('Magento\\Sales\\Model\\OrderFactory', ['create'], [], '', false);
     $this->copyMock = $this->getMock('Magento\\Framework\\Object\\Copy', [], [], '', false);
     $this->messageManagerMock = $this->getMock('Magento\\Framework\\Message\\ManagerInterface');
     $this->customerFormFactoryMock = $this->getMock('Magento\\Customer\\Model\\FormFactory', ['create'], [], '', false);
     $this->customerDataFactoryMock = $this->getMock('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', [], [], '', false);
     $this->randomMock = $this->getMock('Magento\\Framework\\Math\\Random');
     $this->encryptorMock = $this->getMock('Magento\\Framework\\Encryption\\EncryptorInterface');
     $this->customerRepositoryMock = $this->getMockForAbstractClass('\\Magento\\Customer\\Api\\CustomerRepositoryInterface', [], '', false);
     $orderSenderMock = $this->getMock('\\Magento\\Sales\\Model\\Order\\Email\\Sender\\OrderSender', [], [], '', false);
     $this->quoteRepositoryMock = $this->getMock('Magento\\Quote\\Model\\QuoteRepository', [], [], '', false);
     $this->extensibleDataObjectConverterMock = $this->getMockBuilder('Magento\\Framework\\Api\\ExtensibleDataObjectConverter')->setMethods(['toFlatArray'])->disableOriginalConstructor()->getMock();
     $this->extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->will($this->returnValue([]));
     $this->objectManagerHelper = new ObjectManagerHelper($this);
     $this->onepage = $this->objectManagerHelper->getObject('Magento\\Checkout\\Model\\Type\\Onepage', ['eventManager' => $this->eventManagerMock, 'helper' => $this->checkoutHelperMock, 'customerUrl' => $this->customerUrlMock, 'logger' => $this->loggerMock, 'checkoutSession' => $this->checkoutSessionMock, 'customerSession' => $this->customerSessionMock, 'storeManager' => $this->storeManagerMock, 'request' => $this->requestMock, 'customrAddrFactory' => $this->addressFactoryMock, 'customerFormFactory' => $this->customerFormFactoryMock, 'customerFactory' => $this->customerFactoryMock, 'orderFactory' => $this->orderFactoryMock, 'objectCopyService' => $this->copyMock, 'messageManager' => $this->messageManagerMock, 'formFactory' => $this->formFactoryMock, 'customerDataFactory' => $this->customerDataFactoryMock, 'mathRandom' => $this->randomMock, 'encryptor' => $this->encryptorMock, 'addressRepository' => $this->addressRepositoryMock, 'accountManagement' => $this->accountManagementMock, 'orderSenderMock' => $orderSenderMock, 'customerRepository' => $this->customerRepositoryMock, 'extensibleDataObjectConverter' => $this->extensibleDataObjectConverterMock, 'quoteRepository' => $this->quoteRepositoryMock, 'quoteManagement' => $this->quoteManagementMock]);
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:34,代码来源:OnepageTest.php


示例2: processDataObject

 /**
  * Convert data object to array and process available custom attributes
  *
  * @param array $dataObjectArray
  * @return array
  */
 protected function processDataObject($dataObjectArray)
 {
     if (isset($dataObjectArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY])) {
         $dataObjectArray = ExtensibleDataObjectConverter::convertCustomAttributesToSequentialArray($dataObjectArray);
     }
     //Check for nested custom_attributes
     foreach ($dataObjectArray as $key => $value) {
         if (is_array($value)) {
             $dataObjectArray[$key] = $this->processDataObject($value);
         }
     }
     return $dataObjectArray;
 }
开发者ID:opexsw,项目名称:magento2,代码行数:19,代码来源:ServiceOutputProcessor.php


示例3: convertKeysToCamelCase

 /**
  * Convert keys to camelCase
  *
  * @param array $dataArray
  * @return \stdClass
  */
 public function convertKeysToCamelCase(array $dataArray)
 {
     $response = [];
     if (isset($dataArray[AbstractExtensibleObject::CUSTOM_ATTRIBUTES_KEY])) {
         $dataArray = ExtensibleDataObjectConverter::convertCustomAttributesToSequentialArray($dataArray);
     }
     foreach ($dataArray as $fieldName => $fieldValue) {
         if (is_array($fieldValue) && !$this->_isSimpleSequentialArray($fieldValue)) {
             $fieldValue = $this->convertKeysToCamelCase($fieldValue);
         }
         $fieldName = lcfirst(str_replace(' ', '', ucwords(str_replace('_', ' ', $fieldName))));
         $response[$fieldName] = $fieldValue;
     }
     return $response;
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:21,代码来源:SimpleDataObjectConverter.php


示例4: testGetCustomerAttributeMetadata

 /**
  * @magentoDataFixture Magento/Customer/_files/customer.php
  */
 public function testGetCustomerAttributeMetadata()
 {
     // Expect these attributes to exist but do not check the value
     $expectAttrsWOutVals = ['created_at', 'updated_at'];
     // Expect these attributes to exist and check the value - values come from _files/customer.php
     $expectAttrsWithVals = ['id' => 1, 'website_id' => 1, 'store_id' => 1, 'group_id' => 1, 'prefix' => 'Mr.', 'firstname' => 'John', 'middlename' => 'A', 'lastname' => 'Smith', 'suffix' => 'Esq.', 'email' => '[email protected]', 'default_billing' => '1', 'default_shipping' => '1', 'disable_auto_group_change' => 0, 'taxvat' => '12', 'gender' => 0];
     $customer = $this->customerRepository->getById(1);
     $this->assertNotNull($customer);
     $attributes = $this->_extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $this->assertNotEmpty($attributes);
     foreach ($attributes as $attributeCode => $attributeValue) {
         $this->assertNotNull($attributeCode);
         $this->assertNotNull($attributeValue);
         $attributeMetadata = $this->_service->getAttributeMetadata($attributeCode);
         $attrMetadataCode = $attributeMetadata->getAttributeCode();
         $this->assertSame($attributeCode, $attrMetadataCode);
         if (($key = array_search($attrMetadataCode, $expectAttrsWOutVals)) !== false) {
             unset($expectAttrsWOutVals[$key]);
         } else {
             $this->assertArrayHasKey($attrMetadataCode, $expectAttrsWithVals);
             $this->assertSame($expectAttrsWithVals[$attrMetadataCode], $attributeValue, "Failed for {$attrMetadataCode}");
             unset($expectAttrsWithVals[$attrMetadataCode]);
         }
     }
     $this->assertEmpty($expectAttrsWOutVals);
     $this->assertEmpty($expectAttrsWithVals);
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:30,代码来源:CustomerMetadataTest.php


示例5: testGetProductWeeeAttributes

 public function testGetProductWeeeAttributes()
 {
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $customerMetadataService = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\CustomerMetadataInterface');
     $customerFactory = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['metadataService' => $customerMetadataService]);
     $dataObjectHelper = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\DataObjectHelper');
     $expected = $this->_extensibleDataObjectConverter->toFlatArray($customerRepository->getById(1), [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $customerDataSet = $customerFactory->create();
     $dataObjectHelper->populateWithArray($customerDataSet, $expected, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $fixtureGroupCode = 'custom_group';
     $fixtureTaxClassId = 3;
     /** @var \Magento\Customer\Model\Group $group */
     $group = Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Group');
     $fixtureGroupId = $group->load($fixtureGroupCode, 'customer_group_code')->getId();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\Quote');
     $quote->setCustomerGroupId($fixtureGroupId);
     $quote->setCustomerTaxClassId($fixtureTaxClassId);
     $quote->setCustomer($customerDataSet);
     $shipping = new \Magento\Framework\DataObject(['quote' => $quote]);
     $productRepository = Bootstrap::getObjectManager()->create('Magento\\Catalog\\Api\\ProductRepositoryInterface');
     $product = $productRepository->get('simple-with-ftp');
     $amount = $this->_model->getProductWeeeAttributes($product, $shipping, null, null, true);
     $this->assertTrue(is_array($amount));
     $this->assertArrayHasKey(0, $amount);
     $this->assertEquals(12.7, $amount[0]->getAmount());
 }
开发者ID:Doability,项目名称:magento2dev,代码行数:28,代码来源:TaxTest.php


示例6: testGetProductWeeeAttributes

 public function testGetProductWeeeAttributes()
 {
     /** @var \Magento\Customer\Api\CustomerRepositoryInterface $customerRepository */
     $customerRepository = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\CustomerRepositoryInterface');
     $customerMetadataService = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\CustomerMetadataInterface');
     $customerFactory = Bootstrap::getObjectManager()->create('Magento\\Customer\\Api\\Data\\CustomerInterfaceFactory', ['metadataService' => $customerMetadataService]);
     $dataObjectHelper = Bootstrap::getObjectManager()->create('Magento\\Framework\\Api\\DataObjectHelper');
     $expected = $this->_extensibleDataObjectConverter->toFlatArray($customerRepository->getById(1), [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $customerDataSet = $customerFactory->create();
     $dataObjectHelper->populateWithArray($customerDataSet, $expected, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $fixtureGroupCode = 'custom_group';
     $fixtureTaxClassId = 3;
     /** @var \Magento\Customer\Model\Group $group */
     $group = Bootstrap::getObjectManager()->create('Magento\\Customer\\Model\\Group');
     $fixtureGroupId = $group->load($fixtureGroupCode, 'customer_group_code')->getId();
     /** @var \Magento\Quote\Model\Quote $quote */
     $quote = Bootstrap::getObjectManager()->create('Magento\\Quote\\Model\\Quote');
     $quote->setCustomerGroupId($fixtureGroupId);
     $quote->setCustomerTaxClassId($fixtureTaxClassId);
     $quote->setCustomer($customerDataSet);
     $shipping = new \Magento\Framework\Object(['quote' => $quote]);
     $product = Bootstrap::getObjectManager()->create('Magento\\Catalog\\Model\\Product');
     $product->load(1);
     $weeeTax = Bootstrap::getObjectManager()->create('Magento\\Weee\\Model\\Tax');
     $weeeTaxData = ['website_id' => '1', 'entity_id' => '1', 'country' => 'US', 'value' => '12.4', 'state' => '0', 'attribute_id' => '73', 'entity_type_id' => '0'];
     $weeeTax->setData($weeeTaxData);
     $weeeTax->save();
     $amount = $this->_model->getProductWeeeAttributes($product, $shipping);
     $this->assertEquals('12.4000', $amount[0]->getAmount());
 }
开发者ID:nja78,项目名称:magento2,代码行数:30,代码来源:TaxTest.php


示例7: 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


示例8: testToFlatArray

 public function testToFlatArray()
 {
     $expectedResultWithoutStreet = ['id' => 1, 'default_shipping' => false, 'default_billing' => true, 'firstname' => 'John', 'lastname' => 'Doe', 'city' => 'Austin', 'country_id' => 'US', 'region_id' => 1, 'region' => 'Texas', 'region_code' => 'TX'];
     $expectedResultWithStreet = array_merge($expectedResultWithoutStreet, ['street' => ['7700 W Parmer Ln', 'Austin, TX']]);
     $this->extensibleObjectConverter->expects($this->once())->method('toFlatArray')->willReturn($expectedResultWithoutStreet);
     $addressData = $this->createAddressMock();
     $result = $this->addressMapper->toFlatArray($addressData);
     $this->assertEquals($expectedResultWithStreet, $result);
 }
开发者ID:IlyaGluschenko,项目名称:protection,代码行数:9,代码来源:MapperTest.php


示例9: _prepareForm

 /**
  * Prepare the form.
  *
  * @return $this
  */
 protected function _prepareForm()
 {
     /** @var \Magento\Framework\Data\Form $form */
     $form = $this->_formFactory->create(['data' => ['id' => 'edit_form', 'action' => $this->getUrl('customer/*/save'), 'method' => 'post', 'enctype' => 'multipart/form-data']]);
     $customerId = $this->_coreRegistry->registry(RegistryConstants::CURRENT_CUSTOMER_ID);
     if ($customerId) {
         $form->addField('id', 'hidden', ['name' => 'customer_id']);
         $customer = $this->_customerRepository->getById($customerId);
         $form->setValues($this->_extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'))->addValues(['customer_id' => $customerId]);
     }
     $form->setUseContainer(true);
     $this->setForm($form);
     return parent::_prepareForm();
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:19,代码来源:Form.php


示例10: toFlatArray

 /**
  * Convert address data object to a flat array
  *
  * @param AddressInterface $addressDataObject
  * @return array
  * TODO:: Add concrete type of AddressInterface for $addressDataObject parameter once
  * all references have been refactored.
  */
 public function toFlatArray($addressDataObject)
 {
     $flatAddressArray = $this->extensibleDataObjectConverter->toFlatArray($addressDataObject, [], '\\Magento\\Customer\\Api\\Data\\AddressInterface');
     //preserve street
     $street = $addressDataObject->getStreet();
     if (!empty($street) && is_array($street)) {
         // Unset flat street data
         $streetKeys = array_keys($street);
         foreach ($streetKeys as $key) {
             unset($flatAddressArray[$key]);
         }
         //Restore street as an array
         $flatAddressArray[AddressInterface::STREET] = $street;
     }
     return $flatAddressArray;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:24,代码来源:Mapper.php


示例11: save

 /**
  * {@inheritdoc}
  */
 public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false)
 {
     if ($saveOptions) {
         $productOptions = $product->getProductOptions();
     }
     $groupPrices = $product->getData('group_price');
     $tierPrices = $product->getData('tier_price');
     $productId = $this->resourceModel->getIdBySku($product->getSku());
     $productDataArray = $this->extensibleDataObjectConverter->toNestedArray($product, [], 'Magento\\Catalog\\Api\\Data\\ProductInterface');
     $product = $this->initializeProductData($productDataArray, empty($productId));
     $validationResult = $this->resourceModel->validate($product);
     if (true !== $validationResult) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Invalid product data: %1', implode(',', $validationResult)));
     }
     try {
         if ($saveOptions) {
             $product->setProductOptions($productOptions);
             $product->setCanSaveCustomOptions(true);
         }
         $product->setData('group_price', $groupPrices);
         $product->setData('tier_price', $tierPrices);
         $this->resourceModel->save($product);
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) {
         throw \Magento\Framework\Exception\InputException::invalidFieldValue($exception->getAttributeCode(), $product->getData($exception->getAttributeCode()), $exception);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Unable to save product'));
     }
     unset($this->instances[$product->getSku()]);
     unset($this->instancesById[$product->getId()]);
     return $product;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:34,代码来源:ProductRepository.php


示例12: testCreateNonexistingCustomer

 /**
  * @magentoAppArea frontend
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @magentoDbIsolation enabled
  */
 public function testCreateNonexistingCustomer()
 {
     $existingCustId = 1;
     $existingCustomer = $this->customerRepository->getById($existingCustId);
     $email = '[email protected]';
     $firstName = 'Firstsave';
     $lastName = 'Lastsave';
     $customerData = array_merge($existingCustomer->__toArray(), ['email' => $email, 'firstname' => $firstName, 'lastname' => $lastName, 'id' => null]);
     $customerEntity = $this->customerFactory->create();
     $this->dataObjectHelper->populateWithArray($customerEntity, $customerData, '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $customerAfter = $this->accountManagement->createAccount($customerEntity, 'aPassword');
     $this->assertGreaterThan(0, $customerAfter->getId());
     $this->assertEquals($email, $customerAfter->getEmail());
     $this->assertEquals($firstName, $customerAfter->getFirstname());
     $this->assertEquals($lastName, $customerAfter->getLastname());
     $this->accountManagement->authenticate($customerAfter->getEmail(), 'aPassword');
     $attributesBefore = $this->extensibleDataObjectConverter->toFlatArray($existingCustomer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     $attributesAfter = $this->extensibleDataObjectConverter->toFlatArray($customerAfter, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     // ignore 'updated_at'
     unset($attributesBefore['updated_at']);
     unset($attributesAfter['updated_at']);
     $inBeforeOnly = array_diff_assoc($attributesBefore, $attributesAfter);
     $inAfterOnly = array_diff_assoc($attributesAfter, $attributesBefore);
     $expectedInBefore = ['email', 'firstname', 'id', 'lastname'];
     sort($expectedInBefore);
     $actualInBeforeOnly = array_keys($inBeforeOnly);
     sort($actualInBeforeOnly);
     $this->assertEquals($expectedInBefore, $actualInBeforeOnly);
     $expectedInAfter = ['created_in', 'email', 'firstname', 'id', 'lastname'];
     sort($expectedInAfter);
     $actualInAfterOnly = array_keys($inAfterOnly);
     sort($actualInAfterOnly);
     $this->assertEquals($expectedInAfter, $actualInAfterOnly);
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:39,代码来源:AccountManagementTest.php


示例13: _getCustomerForm

 /**
  * Initialize customer form
  *
  * @return \Magento\Customer\Model\Metadata\Form $customerForm
  */
 protected function _getCustomerForm()
 {
     if ($this->_customerForm === null) {
         $this->_customerForm = $this->_customerFormFactory->create('customer', 'adminhtml_customer', $this->_extensibleDataObjectConverter->toFlatArray($this->_getCustomerDataObject()));
     }
     return $this->_customerForm;
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:12,代码来源:Account.php


示例14: save

 /**
  * {@inheritdoc}
  * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  * @SuppressWarnings(PHPMD.NPathComplexity)
  */
 public function save(\Magento\Catalog\Api\Data\ProductInterface $product, $saveOptions = false)
 {
     if ($saveOptions) {
         $productOptions = $product->getProductOptions();
     }
     $isDeleteOptions = $product->getIsDeleteOptions();
     $tierPrices = $product->getData('tier_price');
     $productId = $this->resourceModel->getIdBySku($product->getSku());
     $ignoreLinksFlag = $product->getData('ignore_links_flag');
     $productDataArray = $this->extensibleDataObjectConverter->toNestedArray($product, [], 'Magento\\Catalog\\Api\\Data\\ProductInterface');
     $productLinks = null;
     if (!$ignoreLinksFlag && $ignoreLinksFlag !== null) {
         $productLinks = $product->getProductLinks();
     }
     $productDataArray['store_id'] = (int) $this->storeManager->getStore()->getId();
     $product = $this->initializeProductData($productDataArray, empty($productId));
     if (isset($productDataArray['options'])) {
         if (!empty($productDataArray['options']) || $isDeleteOptions) {
             $this->processOptions($product, $productDataArray['options']);
             $product->setCanSaveCustomOptions(true);
         }
     }
     $this->processLinks($product, $productLinks);
     if (isset($productDataArray['media_gallery_entries'])) {
         $this->processMediaGallery($product, $productDataArray['media_gallery_entries']);
     }
     $validationResult = $this->resourceModel->validate($product);
     if (true !== $validationResult) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Invalid product data: %1', implode(',', $validationResult)));
     }
     try {
         if ($saveOptions) {
             $product->setProductOptions($productOptions);
             $product->setCanSaveCustomOptions(true);
         }
         if ($tierPrices !== null) {
             $product->setData('tier_price', $tierPrices);
         }
         $this->resourceModel->save($product);
     } catch (\Magento\Eav\Model\Entity\Attribute\Exception $exception) {
         throw \Magento\Framework\Exception\InputException::invalidFieldValue($exception->getAttributeCode(), $product->getData($exception->getAttributeCode()), $exception);
     } catch (\Exception $e) {
         throw new \Magento\Framework\Exception\CouldNotSaveException(__('Unable to save product'));
     }
     unset($this->instances[$product->getSku()]);
     unset($this->instancesById[$product->getId()]);
     return $this->get($product->getSku());
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:53,代码来源:ProductRepository.php


示例15: testExecuteWithException

 public function testExecuteWithException()
 {
     $this->request->expects($this->once())->method('getPost')->willReturn(null);
     $this->form->expects($this->once())->method('setInvisibleIgnored');
     $this->form->expects($this->atLeastOnce())->method('extractData')->willReturn([]);
     $this->form->expects($this->never())->method('validateData');
     $this->extensibleDataObjectConverter->expects($this->once())->method('toFlatArray')->willReturn([]);
     $validationResult = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\ValidationResultsInterface', [], '', false, true, true);
     $error = $this->getMock('Magento\\Framework\\Message\\Error', [], [], '', false);
     $error->expects($this->once())->method('getText')->willReturn('Error text');
     $exception = $this->getMock('Magento\\Framework\\Validator\\Exception', [], [], '', false);
     $exception->expects($this->once())->method('getMessages')->willReturn([$error]);
     $validationResult->expects($this->once())->method('getMessages')->willThrowException($exception);
     $this->customerAccountManagement->expects($this->once())->method('validate')->willReturn($validationResult);
     $this->controller->execute();
 }
开发者ID:pradeep-wagento,项目名称:magento2,代码行数:16,代码来源:ValidateTest.php


示例16: _setupStoreMode

 /**
  * @param $customerData
  * @param $isSingleStoreMode
  * @param $canModifyCustomer
  *
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 private function _setupStoreMode($customerData, $isSingleStoreMode, $canModifyCustomer)
 {
     $backendSessionMock = $this->getMock('\\Magento\\Backend\\Model\\Session', ['getCustomerData'], [], '', false);
     $backendSessionMock->expects($this->any())->method('getCustomerData')->will($this->returnValue([]));
     $layoutMock = $this->getMock('\\Magento\\Framework\\View\\Layout\\Element\\Layout', ['createBlock'], [], '', false);
     $layoutMock->expects($this->at(0))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Group')));
     $layoutMock->expects($this->at(1))->method('createBlock')->with('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Backend\\Block\\Store\\Switcher\\Form\\Renderer\\Fieldset\\Element')));
     if (empty($customerData['id'])) {
         $layoutMock->expects($this->at(2))->method('createBlock')->with('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail')->will($this->returnValue($this->objectManagerHelper->getObject('Magento\\Customer\\Block\\Adminhtml\\Edit\\Renderer\\Attribute\\Sendemail')));
     }
     $urlBuilderMock = $this->getMock('\\Magento\\Backend\\Model\\Url', ['getBaseUrl'], [], '', false);
     $urlBuilderMock->expects($this->once())->method('getBaseUrl')->will($this->returnValue('someUrl'));
     $storeManagerMock = $this->getMock('Magento\\Store\\Model\\StoreManager', [], [], '', false);
     $storeManagerMock->expects($this->any())->method('isSingleStoreMode')->will($this->returnValue($isSingleStoreMode));
     $customerObject = $this->getMock('\\Magento\\Customer\\Api\\Data\\CustomerInterface');
     if (!empty($customerData['id'])) {
         $customerObject->expects($this->any())->method('getId')->will($this->returnValue($customerData['id']));
     }
     $fieldset = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Fieldset')->setMethods(['getForm', 'addField', 'removeField'])->disableOriginalConstructor()->getMock();
     $accountForm = $this->getMockBuilder('Magento\\Framework\\Data\\Form')->setMethods(['create', 'addFieldset', 'getElement', 'setValues'])->disableOriginalConstructor()->getMock();
     $accountForm->expects($this->any())->method('addFieldset')->with('base_fieldset')->will($this->returnValue($fieldset));
     $accountForm->expects($this->any())->method('setValues')->will($this->returnValue($accountForm));
     $fieldset->expects($this->any())->method('getForm')->will($this->returnValue($accountForm));
     $formElement = $this->getMockBuilder('\\Magento\\Framework\\Data\\Form\\Element\\Select')->setMethods(['setRenderer', 'addClass', 'setDisabled'])->disableOriginalConstructor()->getMock();
     $formElement->expects($this->any())->method('setRenderer')->will($this->returnValue(null));
     $formElement->expects($this->any())->method('addClass')->will($this->returnValue(null));
     $formElement->expects($this->any())->method('setDisabled')->will($this->returnValue(null));
     $accountForm->expects($this->any())->method('getElement')->withAnyParameters()->will($this->returnValue($formElement));
     $fieldset->expects($this->any())->method('addField')->will($this->returnValue($formElement));
     $customerForm = $this->getMock('\\Magento\\Customer\\Model\\Metadata\\Form', ['getAttributes'], [], '', false);
     $customerForm->expects($this->any())->method('getAttributes')->will($this->returnValue([]));
     $this->contextMock->expects($this->any())->method('getBackendSession')->will($this->returnValue($backendSessionMock));
     $this->contextMock->expects($this->any())->method('getLayout')->will($this->returnValue($layoutMock));
     $this->contextMock->expects($this->any())->method('getUrlBuilder')->will($this->returnValue($urlBuilderMock));
     $this->contextMock->expects($this->any())->method('getStoreManager')->will($this->returnValue($storeManagerMock));
     $this->customerFactoryMock->expects($this->any())->method('create')->will($this->returnValue($customerObject));
     $this->dataObjectHelperMock->expects($this->once())->method('populateWithArray');
     $this->options->expects($this->any())->method('getNamePrefixOptions')->will($this->returnValue(['Pref1', 'Pref2']));
     $this->options->expects($this->any())->method('getNameSuffixOptions')->will($this->returnValue(['Suf1', 'Suf2']));
     $this->formFactoryMock->expects($this->any())->method('create')->will($this->returnValue($accountForm));
     $this->extensibleDataObjectConverterMock->expects($this->any())->method('toFlatArray')->will($this->returnValue($customerData));
     $this->customerFormFactoryMock->expects($this->any())->method('create')->with('customer', 'adminhtml_customer', $this->extensibleDataObjectConverterMock->toFlatArray($customerObject, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface'))->will($this->returnValue($customerForm));
     $this->accountManagementMock->expects($this->any())->method('isReadOnly')->withAnyParameters()->will($this->returnValue(!$canModifyCustomer));
     $this->accountManagementMock->expects($this->any())->method('getConfirmationStatus')->withAnyParameters()->will($this->returnValue(AccountManagementInterface::ACCOUNT_CONFIRMED));
 }
开发者ID:shabbirvividads,项目名称:magento2,代码行数:52,代码来源:AccountTest.php


示例17: getFormValues

 /**
  * Return Form Elements values
  *
  * @return array
  */
 public function getFormValues()
 {
     try {
         $customer = $this->customerRepository->getById($this->getCustomerId());
     } catch (\Exception $e) {
         /** If customer does not exist do nothing. */
     }
     $data = isset($customer) ? $this->_extensibleDataObjectConverter->toFlatArray($customer, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface') : [];
     foreach ($this->getQuote()->getData() as $key => $value) {
         if (strpos($key, 'customer_') === 0) {
             $data[substr($key, 9)] = $value;
         }
     }
     if ($this->getQuote()->getCustomerEmail()) {
         $data['email'] = $this->getQuote()->getCustomerEmail();
     }
     return $data;
 }
开发者ID:kidaa30,项目名称:magento2-platformsh,代码行数:23,代码来源:Account.php


示例18: testSaveWithPasswordHash

 /**
  * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  */
 public function testSaveWithPasswordHash()
 {
     $customerId = 1;
     $storeId = 2;
     $passwordHash = 'ukfa4sdfa56s5df02asdf4rt';
     $this->prepareMocksForValidation(true);
     $region = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\RegionInterface', [], '', false);
     $address = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false, false, true, ['setCustomerId', 'setRegion', 'getRegion', 'getId']);
     $address2 = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false, false, true, ['setCustomerId', 'setRegion', 'getRegion', 'getId']);
     $customerModel = $this->getMock('Magento\\Customer\\Model\\Customer', ['getId', 'setId', 'setStoreId', 'getStoreId', 'getAttributeSetId', 'setAttributeSetId', 'setRpToken', 'setRpTokenCreatedAt', 'getDataModel', 'setPasswordHash'], [], '', false);
     $customerAttributesMetaData = $this->getMockForAbstractClass('Magento\\Framework\\Api\\CustomAttributesDataInterface', [], '', false, false, true, ['getId', 'getEmail', 'getWebsiteId', 'getAddresses', 'setAddresses']);
     $this->customer->expects($this->atLeastOnce())->method('getId')->willReturn($customerId);
     $this->customerRegistry->expects($this->atLeastOnce())->method('retrieve')->with($customerId)->willReturn($customerModel);
     $customerModel->expects($this->atLeastOnce())->method('getDataModel')->willReturn($this->customer);
     $this->imageProcessor->expects($this->once())->method('save')->with($this->customer, CustomerMetadataInterface::ENTITY_TYPE_CUSTOMER, $this->customer)->willReturn($customerAttributesMetaData);
     $address->expects($this->once())->method('setCustomerId')->with($customerId)->willReturnSelf();
     $address->expects($this->once())->method('getRegion')->willReturn($region);
     $address->expects($this->atLeastOnce())->method('getId')->willReturn(7);
     $address->expects($this->once())->method('setRegion')->with($region);
     $customerAttributesMetaData->expects($this->any())->method('getAddresses')->willReturn([$address]);
     $customerAttributesMetaData->expects($this->at(1))->method('setAddresses')->with([]);
     $customerAttributesMetaData->expects($this->at(2))->method('setAddresses')->with([$address]);
     $this->extensibleDataObjectConverter->expects($this->once())->method('toNestedArray')->with($customerAttributesMetaData, [], '\\Magento\\Customer\\Api\\Data\\CustomerInterface')->willReturn(['customerData']);
     $this->customerFactory->expects($this->once())->method('create')->with(['data' => ['customerData']])->willReturn($customerModel);
     $customerModel->expects($this->once())->method('getStoreId')->willReturn(null);
     $store = $this->getMock('Magento\\Store\\Model\\Store', [], [], '', false);
     $store->expects($this->once())->method('getId')->willReturn($storeId);
     $this->storeManager->expects($this->once())->method('getStore')->willReturn($store);
     $customerModel->expects($this->once())->method('setStoreId')->with($storeId);
     $customerModel->expects($this->once())->method('setId')->with(null);
     $customerModel->expects($this->once())->method('getAttributeSetId')->willReturn(null);
     $customerModel->expects($this->once())->method('setAttributeSetId')->with(\Magento\Customer\Api\CustomerMetadataInterface::ATTRIBUTE_SET_ID_CUSTOMER);
     $customerModel->expects($this->once())->method('setPasswordHash')->with($passwordHash);
     $customerModel->expects($this->atLeastOnce())->method('getId')->willReturn($customerId);
     $this->customerResourceModel->expects($this->once())->method('save')->with($customerModel);
     $this->customerRegistry->expects($this->once())->method('push')->with($customerModel);
     $this->customer->expects($this->any())->method('getAddresses')->willReturn([$address, $address2]);
     $this->addressRepository->expects($this->once())->method('save')->with($address);
     $customerAttributesMetaData->expects($this->once())->method('getEmail')->willReturn('[email protected]');
     $customerAttributesMetaData->expects($this->once())->method('getWebsiteId')->willReturn(2);
     $this->customerRegistry->expects($this->once())->method('retrieveByEmail')->with('[email protected]', 2)->willReturn($customerModel);
     $this->eventManager->expects($this->once())->method('dispatch')->with('customer_save_after_data_object', ['customer_data_object' => $this->customer, 'orig_customer_data_object' => $customerAttributesMetaData]);
     $this->model->save($this->customer, $passwordHash);
 }
开发者ID:whoople,项目名称:magento2-testing,代码行数:47,代码来源:CustomerRepositoryTest.php


示例19: testUpdateCustomer

 /**
  * @dataProvider updateCustomerDataProvider
  * @magentoAppArea frontend
  * @magentoDataFixture Magento/Customer/_files/customer.php
  * @param int|null $defaultBilling
  * @param int|null $defaultShipping
  */
 public function testUpdateCustomer($defaultBilling, $defaultShipping)
 {
     $existingCustomerId = 1;
     $email = '[email protected]';
     $firstName = 'Firstsave';
     $lastName = 'Lastsave';
     $customerBefore = $this->customerRepository->getById($existingCustomerId);
     $customerData = array_merge($customerBefore->__toArray(), ['id' => 1, 'email' => $email, 'firstname' => $first 

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
PHP Api\FilterBuilder类代码示例发布时间:2022-05-23
下一篇:
PHP Api\DataObjectHelper类代码示例发布时间: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