本文整理汇总了PHP中Magento\Framework\Api\DataObjectHelper::mergeDataObjects方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectHelper::mergeDataObjects方法的具体用法?PHP DataObjectHelper::mergeDataObjects怎么用?PHP DataObjectHelper::mergeDataObjects使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\DataObjectHelper
的用法示例。
在下文中一共展示了DataObjectHelper::mergeDataObjects方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _createSecondAddress
/**
* Helper function that returns an Address Data Object that matches the data from customer_two_address fixture
*
* @return \Magento\Customer\Api\Data\AddressInterface
*/
private function _createSecondAddress()
{
$address = $this->_addressFactory->create();
$this->dataObjectHelper->mergeDataObjects('\\Magento\\Customer\\Api\\Data\\AddressInterface', $address, $this->_expectedAddresses[1]);
$address->setId(null);
$address->setRegion($this->_expectedAddresses[1]->getRegion());
return $address;
}
示例2: testCreateCustomerNewThenUpdateFirstName
/**
* @magentoDbIsolation enabled
*/
public function testCreateCustomerNewThenUpdateFirstName()
{
/** Create a new customer */
$email = 'first_last@example.com';
$storeId = 1;
$firstname = 'Tester';
$lastname = 'McTest';
$groupId = 1;
$newCustomerEntity = $this->customerFactory->create()->setStoreId($storeId)->setEmail($email)->setFirstname($firstname)->setLastname($lastname)->setGroupId($groupId);
$customer = $this->customerRepository->save($newCustomerEntity);
/** Update customer */
$newCustomerFirstname = 'New First Name';
$updatedCustomer = $this->customerFactory->create();
$this->dataObjectHelper->mergeDataObjects('\\Magento\\Customer\\Api\\Data\\CustomerInterface', $updatedCustomer, $customer);
$updatedCustomer->setFirstname($newCustomerFirstname);
$this->customerRepository->save($updatedCustomer);
/** Check if update was successful */
$customer = $this->customerRepository->get($customer->getEmail());
$this->assertEquals($newCustomerFirstname, $customer->getFirstname());
$this->assertEquals($lastname, $customer->getLastname());
}
示例3: testCreateNewCustomerFromClone
/**
* @magentoAppArea frontend
* @magentoDataFixture Magento/Customer/_files/customer.php
*/
public function testCreateNewCustomerFromClone()
{
$email = 'savecustomer@example.com';
$firstName = 'Firstsave';
$lastname = 'Lastsave';
$existingCustId = 1;
$existingCustomer = $this->customerRepository->getById($existingCustId);
$customerEntity = $this->customerFactory->create();
$this->dataObjectHelper->mergeDataObjects('\\Magento\\Customer\\Api\\Data\\CustomerInterface', $customerEntity, $existingCustomer);
$customerEntity->setEmail($email)->setFirstname($firstName)->setLastname($lastname)->setId(null);
$customer = $this->accountManagement->createAccount($customerEntity, 'aPassword');
$this->assertNotEmpty($customer->getId());
$this->assertEquals($email, $customer->getEmail());
$this->assertEquals($firstName, $customer->getFirstname());
$this->assertEquals($lastname, $customer->getLastname());
$this->accountManagement->authenticate($customer->getEmail(), 'aPassword', true);
}
示例4: submitQuote
/**
* Submit quote
*
* @param Quote $quote
* @param array $orderData
* @return \Magento\Framework\Model\AbstractExtensibleModel|\Magento\Sales\Api\Data\OrderInterface|object
* @throws \Exception
* @throws \Magento\Framework\Exception\LocalizedException
*/
protected function submitQuote(QuoteEntity $quote, $orderData = [])
{
$order = $this->orderFactory->create();
$this->quoteValidator->validateBeforeSubmit($quote);
if (!$quote->getCustomerIsGuest()) {
if ($quote->getCustomerId()) {
$this->_prepareCustomerQuote($quote);
}
$this->customerManagement->populateCustomerInfo($quote);
}
$addresses = [];
$quote->reserveOrderId();
if ($quote->isVirtual()) {
$this->dataObjectHelper->mergeDataObjects('\\Magento\\Sales\\Api\\Data\\OrderInterface', $order, $this->quoteAddressToOrder->convert($quote->getBillingAddress(), $orderData));
} else {
$this->dataObjectHelper->mergeDataObjects('\\Magento\\Sales\\Api\\Data\\OrderInterface', $order, $this->quoteAddressToOrder->convert($quote->getShippingAddress(), $orderData));
$shippingAddress = $this->quoteAddressToOrderAddress->convert($quote->getShippingAddress(), ['address_type' => 'shipping', 'email' => $quote->getCustomerEmail()]);
$addresses[] = $shippingAddress;
$order->setShippingAddress($shippingAddress);
}
$billingAddress = $this->quoteAddressToOrderAddress->convert($quote->getBillingAddress(), ['address_type' => 'billing', 'email' => $quote->getCustomerEmail()]);
$addresses[] = $billingAddress;
$order->setBillingAddress($billingAddress);
$order->setAddresses($addresses);
$order->setPayments([$this->quotePaymentToOrderPayment->convert($quote->getPayment())]);
$order->setItems($this->resolveItems($quote));
if ($quote->getCustomer()) {
$order->setCustomerId($quote->getCustomer()->getId());
}
$order->setQuoteId($quote->getId());
$order->setCustomerEmail($quote->getCustomerEmail());
$order->setCustomerFirstname($quote->getCustomerFirstname());
$order->setCustomerMiddlename($quote->getCustomerMiddlename());
$order->setCustomerLastname($quote->getCustomerLastname());
$this->eventManager->dispatch('sales_model_service_quote_submit_before', ['order' => $order, 'quote' => $quote]);
try {
$order = $this->orderManagement->place($order);
$quote->setIsActive(false);
$this->eventManager->dispatch('sales_model_service_quote_submit_success', ['order' => $order, 'quote' => $quote]);
$this->quoteRepository->save($quote);
} catch (\Exception $e) {
$this->eventManager->dispatch('sales_model_service_quote_submit_failure', ['order' => $order, 'quote' => $quote]);
throw $e;
}
return $order;
}
示例5: testMergeDataObjects
/**
* @param array $data1
* @param array $data2
* @dataProvider dataProviderForTestMergeDataObjects
*/
public function testMergeDataObjects($data1, $data2)
{
/** @var \Magento\Customer\Model\Data\Address $addressDataObject */
$firstAddressDataObject = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Address', ['dataObjectHelper' => $this->dataObjectHelper]);
/** @var \Magento\Customer\Model\Data\Region $regionDataObject */
$firstRegionDataObject = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Region', ['dataObjectHelper' => $this->dataObjectHelper]);
$firstRegionDataObject->setRegionId($data1['region']['region_id']);
$firstRegionDataObject->setRegion($data1['region']['region']);
if (isset($data1['id'])) {
$firstAddressDataObject->setId($data1['id']);
}
if (isset($data1['country_id'])) {
$firstAddressDataObject->setCountryId($data1['country_id']);
}
$firstAddressDataObject->setStreet($data1['street']);
$firstAddressDataObject->setIsDefaultShipping($data1['default_shipping']);
$firstAddressDataObject->setRegion($firstRegionDataObject);
$secondAddressDataObject = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Address', ['dataObjectHelper' => $this->dataObjectHelper]);
/** @var \Magento\Customer\Model\Data\Region $regionDataObject */
$secondRegionDataObject = $this->objectManager->getObject('Magento\\Customer\\Model\\Data\\Region', ['dataObjectHelper' => $this->dataObjectHelper]);
$secondRegionDataObject->setRegionId($data2['region']['region_id']);
$secondRegionDataObject->setRegion($data2['region']['region']);
if (isset($data2['id'])) {
$secondAddressDataObject->setId($data2['id']);
}
if (isset($data2['country_id'])) {
$secondAddressDataObject->setCountryId($data2['country_id']);
}
$secondAddressDataObject->setStreet($data2['street']);
$secondAddressDataObject->setIsDefaultShipping($data2['default_shipping']);
$secondAddressDataObject->setRegion($secondRegionDataObject);
$this->objectProcessorMock->expects($this->once())->method('buildOutputDataArray')->with($secondAddressDataObject, get_class($firstAddressDataObject))->willReturn($data2);
$this->methodsMapProcessor->expects($this->at(0))->method('getMethodReturnType')->with('Magento\\Customer\\Model\\Data\\Address', 'getStreet')->willReturn('string[]');
$this->methodsMapProcessor->expects($this->at(1))->method('getMethodReturnType')->with('Magento\\Customer\\Model\\Data\\Address', 'getRegion')->willReturn('\\Magento\\Customer\\Api\\Data\\RegionInterface');
$this->objectFactoryMock->expects($this->once())->method('create')->with('\\Magento\\Customer\\Api\\Data\\RegionInterface', [])->willReturn($secondRegionDataObject);
$this->dataObjectHelper->mergeDataObjects(get_class($firstAddressDataObject), $firstAddressDataObject, $secondAddressDataObject);
$this->assertSame($firstAddressDataObject->getId(), $secondAddressDataObject->getId());
$this->assertSame($firstAddressDataObject->getCountryId(), $secondAddressDataObject->getCountryId());
$this->assertSame($firstAddressDataObject->getStreet(), $secondAddressDataObject->getStreet());
$this->assertSame($firstAddressDataObject->isDefaultShipping(), $secondAddressDataObject->isDefaultShipping());
$this->assertSame($firstAddressDataObject->getRegion(), $secondAddressDataObject->getRegion());
}
示例6: _prepareCustomerAddress
/**
* Create customer address and save it in the quote so that it can be used to persist later.
*
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
* @param \Magento\Quote\Model\Quote\Address $quoteCustomerAddress
* @return void
* @throws \InvalidArgumentException
* @SuppressWarnings(PHPMD.CyclomaticComplexity)
*/
protected function _prepareCustomerAddress($customer, $quoteCustomerAddress)
{
// Possible that customerId is null for new customers
$quoteCustomerAddress->setCustomerId($customer->getId());
$customerAddress = $quoteCustomerAddress->exportCustomerAddress();
$quoteAddressId = $quoteCustomerAddress->getCustomerAddressId();
$addressType = $quoteCustomerAddress->getAddressType();
if ($quoteAddressId) {
/** Update existing address */
$existingAddressDataObject = $this->addressRepository->getById($quoteAddressId);
/** Update customer address data */
$this->dataObjectHelper->mergeDataObjects(get_class($existingAddressDataObject), $existingAddressDataObject, $customerAddress);
$customerAddress = $existingAddressDataObject;
} elseif ($addressType == \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING) {
try {
$billingAddressDataObject = $this->accountManagement->getDefaultBillingAddress($customer->getId());
} catch (\Exception $e) {
/** Billing address does not exist. */
}
$isShippingAsBilling = $quoteCustomerAddress->getSameAsBilling();
if (isset($billingAddressDataObject) && $isShippingAsBilling) {
/** Set existing billing address as default shipping */
$customerAddress = $billingAddressDataObject;
$customerAddress->setIsDefaultShipping(true);
}
}
switch ($addressType) {
case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_BILLING:
if (is_null($customer->getDefaultBilling())) {
$customerAddress->setIsDefaultBilling(true);
}
break;
case \Magento\Quote\Model\Quote\Address::ADDRESS_TYPE_SHIPPING:
if (is_null($customer->getDefaultShipping())) {
$customerAddress->setIsDefaultShipping(true);
}
break;
default:
throw new \InvalidArgumentException('Customer address type is invalid.');
}
$this->getQuote()->setCustomer($customer);
$this->getQuote()->addCustomerAddress($customerAddress);
}
示例7: updateCustomerData
/**
* Update customer data object
*
* @param \Magento\Customer\Api\Data\CustomerInterface $customer
* @return $this
*/
public function updateCustomerData(\Magento\Customer\Api\Data\CustomerInterface $customer)
{
$quoteCustomer = $this->getCustomer();
$this->dataObjectHelper->mergeDataObjects(get_class($quoteCustomer), $quoteCustomer, $customer);
$this->setCustomer($quoteCustomer);
return $this;
}