本文整理汇总了PHP中Magento\Customer\Api\AddressRepositoryInterface::getList方法的典型用法代码示例。如果您正苦于以下问题:PHP AddressRepositoryInterface::getList方法的具体用法?PHP AddressRepositoryInterface::getList怎么用?PHP AddressRepositoryInterface::getList使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Magento\Customer\Api\AddressRepositoryInterface
的用法示例。
在下文中一共展示了AddressRepositoryInterface::getList方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: execute
/**
* @return void
*/
public function execute()
{
$filter = $this->filterBuilder->setField('parent_id')->setValue($this->_getCheckout()->getCustomer()->getId())->setConditionType('eq')->create();
$addresses = (array) $this->addressRepository->getList($this->searchCriteriaBuilder->addFilters([$filter])->create())->getItems();
/**
* if we create first address we need reset emd init checkout
*/
if (count($addresses) === 1) {
$this->_getCheckout()->reset();
}
$this->_redirect('*/checkout/addresses');
}
示例2: getAddress
/**
* Get a list of current customer addresses.
*
* @return \Magento\Customer\Api\Data\AddressInterface[]
*/
public function getAddress()
{
$addresses = $this->getData('address_collection');
if ($addresses === null) {
try {
$filter = $this->filterBuilder->setField('parent_id')->setValue($this->_multishipping->getCustomer()->getId())->setConditionType('eq')->create();
$addresses = (array) $this->addressRepository->getList($this->searchCriteriaBuilder->addFilters([$filter])->create())->getItems();
} catch (NoSuchEntityException $e) {
return [];
}
$this->setData('address_collection', $addresses);
}
return $addresses;
}
示例3: testSearchAddresses
/**
* @param \Magento\Framework\Api\Filter[] $filters
* @param \Magento\Framework\Api\Filter[] $filterGroup
* @param \Magento\Framework\Api\SortOrder[] $filterOrders
* @param array $expectedResult array of expected results indexed by ID
*
* @dataProvider searchAddressDataProvider
*
* @magentoDataFixture Magento/Customer/_files/customer.php
* @magentoDataFixture Magento/Customer/_files/customer_two_addresses.php
* @magentoAppIsolation enabled
*/
public function testSearchAddresses($filters, $filterGroup, $filterOrders, $expectedResult)
{
/** @var \Magento\Framework\Api\SearchCriteriaBuilder $searchBuilder */
$searchBuilder = $this->_objectManager->create('Magento\\Framework\\Api\\SearchCriteriaBuilder');
foreach ($filters as $filter) {
$searchBuilder->addFilters([$filter]);
}
if ($filterGroup !== null) {
$searchBuilder->addFilters($filterGroup);
}
if ($filterOrders !== null) {
foreach ($filterOrders as $order) {
$searchBuilder->addSortOrder($order);
}
}
$searchResults = $this->repository->getList($searchBuilder->create());
$this->assertEquals(count($expectedResult), $searchResults->getTotalCount());
$i = 0;
/** @var \Magento\Customer\Api\Data\AddressInterface $item*/
foreach ($searchResults->getItems() as $item) {
$this->assertEquals($expectedResult[$i]['id'], $item->getId());
$this->assertEquals($expectedResult[$i]['city'], $item->getCity());
$this->assertEquals($expectedResult[$i]['postcode'], $item->getPostcode());
$this->assertEquals($expectedResult[$i]['firstname'], $item->getFirstname());
$i++;
}
}
示例4: getAddressCollection
/**
* Retrieve current customer address DATA collection.
*
* @return \Magento\Customer\Api\Data\AddressInterface[]
*/
public function getAddressCollection()
{
if ($this->getCustomerId()) {
$filter = $this->filterBuilder->setField('parent_id')->setValue($this->getCustomerId())->setConditionType('eq')->create();
$this->searchCriteriaBuilder->addFilters([$filter]);
$searchCriteria = $this->searchCriteriaBuilder->create();
$result = $this->addressService->getList($searchCriteria);
return $result->getItems();
}
return [];
}
示例5: getDefaultAddressByDataKey
/**
* Retrieve customer default address by data key
*
* @param string $key
* @param string|null $defaultAddressIdFromCustomer
* @return int|null
*/
private function getDefaultAddressByDataKey($key, $defaultAddressIdFromCustomer)
{
$addressId = $this->getData($key);
if (is_null($addressId)) {
$addressId = $defaultAddressIdFromCustomer;
if (!$addressId) {
/** Default address is not available, try to find any customer address */
$filter = $this->filterBuilder->setField('parent_id')->setValue($this->getCustomer()->getId())->setConditionType('eq')->create();
$addresses = (array) $this->addressRepository->getList($this->searchCriteriaBuilder->addFilters([$filter])->create())->getItems();
if ($addresses) {
$address = reset($addresses);
$addressId = $address->getId();
}
}
$this->setData($key, $addressId);
}
return $addressId;
}