本文整理汇总了PHP中Magento\Framework\Api\DataObjectHelper::populateWithArray方法的典型用法代码示例。如果您正苦于以下问题:PHP DataObjectHelper::populateWithArray方法的具体用法?PHP DataObjectHelper::populateWithArray怎么用?PHP DataObjectHelper::populateWithArray使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Framework\Api\DataObjectHelper
的用法示例。
在下文中一共展示了DataObjectHelper::populateWithArray方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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;
}
示例2: 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;
}
示例3: 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;
}
示例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());
}
示例5: 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;
}
示例6: 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;
}
示例7: 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;
}
示例8: 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;
}
示例9: 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;
}
示例10: convert
/**
* @param Payment $object
* @param array $data
* @return OrderPaymentInterface
*/
public function convert(Payment $object, $data = [])
{
$paymentData = $this->objectCopyService->getDataFromFieldset('quote_convert_payment', 'to_order_payment', $object);
$orderPayment = $this->orderPaymentFactory->create();
$this->dataObjectHelper->populateWithArray($orderPayment, array_merge($paymentData, $data), '\\Magento\\Sales\\Api\\Data\\OrderPaymentInterface');
$orderPayment->setAdditionalInformation(serialize(array_merge($object->getAdditionalInformation(), [Substitution::INFO_KEY_TITLE => $object->getMethodInstance()->getTitle()])));
// set directly on the model
$orderPayment->setCcNumber($object->getCcNumber());
$orderPayment->setCcCid($object->getCcCid());
return $orderPayment;
}
示例11: 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 [];
}
示例12: getItems
/**
* {@inheritdoc}
*/
public function getItems()
{
$types = [];
$inputType = $this->inputTypeFactory->create();
foreach ($inputType->toOptionArray() as $option) {
$type = $this->attributeTypeFactory->create();
$this->dataObjectHelper->populateWithArray($type, $option, '\\Magento\\Catalog\\Api\\Data\\ProductAttributeTypeInterface');
$types[] = $type;
}
return $types;
}
示例13: createTaxRules
/**
* Helper to create tax rules.
*
* @param array $rulesData Keys match populateWithArray
* @return array code => rule id
*/
public function createTaxRules($rulesData)
{
/** @var \Magento\Tax\Api\Data\TaxRuleInterfaceFactory $taxRuleFactory */
$taxRuleFactory = $this->objectManager->create('Magento\\Tax\\Api\\Data\\TaxRuleInterfaceFactory');
/** @var \Magento\Tax\Api\TaxRuleRepositoryInterface $taxRuleService */
$taxRuleService = $this->objectManager->create('Magento\\Tax\\Api\\TaxRuleRepositoryInterface');
$rules = [];
foreach ($rulesData as $ruleData) {
$taxRule = $taxRuleFactory->create();
$this->dataObjectHelper->populateWithArray($taxRule, $ruleData, '\\Magento\\Tax\\Api\\Data\\TaxRuleInterface');
$rules[$ruleData['code']] = $taxRuleService->save($taxRule)->getId();
}
return $rules;
}
示例14: convertTo
/**
* @param Product $product
* @param array $rowData
* @return ProductAttributeMediaGalleryEntryInterface $entry
*/
public function convertTo(Product $product, array $rowData)
{
$image = $rowData;
$productImages = $product->getMediaAttributeValues();
if (!isset($image['types'])) {
$image['types'] = array_keys($productImages, $image['file']);
}
$entry = $this->mediaGalleryEntryFactory->create();
$this->dataObjectHelper->populateWithArray($entry, $image, '\\Magento\\Catalog\\Api\\Data\\ProductAttributeMediaGalleryEntryInterface');
if (isset($image['value_id'])) {
$entry->setId($image['value_id']);
}
return $entry;
}
示例15: getItems
/**
* @param \Magento\Catalog\Api\Data\ProductInterface $product
* @return \Magento\Bundle\Api\Data\OptionInterface[]
*/
public function getItems(\Magento\Catalog\Api\Data\ProductInterface $product)
{
$optionCollection = $this->type->getOptionsCollection($product);
$optionList = [];
/** @var \Magento\Bundle\Model\Option $option */
foreach ($optionCollection as $option) {
$productLinks = $this->linkList->getItems($product, $option->getOptionId());
/** @var \Magento\Bundle\Api\Data\OptionInterface $optionDataObject */
$optionDataObject = $this->optionFactory->create();
$this->dataObjectHelper->populateWithArray($optionDataObject, $option->getData(), '\\Magento\\Bundle\\Api\\Data\\OptionInterface');
$optionDataObject->setOptionId($option->getOptionId())->setTitle($option->getTitle() === null ? $option->getDefaultTitle() : $option->getTitle())->setSku($product->getSku())->setProductLinks($productLinks);
$optionList[] = $optionDataObject;
}
return $optionList;
}