Пример #1
0
 /**
  * Retrieve customers addresses matching the specified criteria.
  *
  * @param SearchCriteriaInterface $searchCriteria
  * @return \Magento\Customer\Api\Data\AddressSearchResultsInterface
  * @throws \Magento\Framework\Exception\LocalizedException
  */
 public function getList(SearchCriteriaInterface $searchCriteria)
 {
     $searchResults = $this->addressSearchResultsFactory->create();
     /** @var Collection $collection */
     $collection = $this->addressCollectionFactory->create();
     $this->extensionAttributesJoinProcessor->process($collection, 'Magento\\Customer\\Api\\Data\\AddressInterface');
     // Add filters from root filter group to the collection
     foreach ($searchCriteria->getFilterGroups() as $group) {
         $this->addFilterGroupToCollection($group, $collection);
     }
     $searchResults->setTotalCount($collection->getSize());
     /** @var SortOrder $sortOrder */
     foreach ((array) $searchCriteria->getSortOrders() as $sortOrder) {
         $field = $sortOrder->getField();
         $collection->addOrder($field, $sortOrder->getDirection() == SortOrder::SORT_ASC ? 'ASC' : 'DESC');
     }
     $collection->setCurPage($searchCriteria->getCurrentPage());
     $collection->setPageSize($searchCriteria->getPageSize());
     /** @var \Magento\Customer\Api\Data\AddressInterface[] $addresses */
     $addresses = [];
     /** @var \Magento\Customer\Model\Address $address */
     foreach ($collection->getItems() as $address) {
         $addresses[] = $this->getById($address->getId());
     }
     $searchResults->setItems($addresses);
     $searchResults->setSearchCriteria($searchCriteria);
     return $searchResults;
 }
 public function testGetList()
 {
     $filterGroup = $this->getMock('Magento\\Framework\\Api\\Search\\FilterGroup', [], [], '', false);
     $filter = $this->getMock('Magento\\Framework\\Api\\Filter', [], [], '', false);
     $collection = $this->getMock('Magento\\Customer\\Model\\ResourceModel\\Address\\Collection', [], [], '', false);
     $searchResults = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressSearchResultsInterface', [], '', false);
     $searchCriteria = $this->getMockForAbstractClass('Magento\\Framework\\Api\\SearchCriteriaInterface', [], '', false);
     $this->addressSearchResultsFactory->expects($this->once())->method('create')->willReturn($searchResults);
     $this->addressCollectionFactory->expects($this->once())->method('create')->willReturn($collection);
     $this->extensionAttributesJoinProcessor->expects($this->once())->method('process')->with($collection, 'Magento\\Customer\\Api\\Data\\AddressInterface');
     $searchCriteria->expects($this->once())->method('getFilterGroups')->willReturn([$filterGroup]);
     $filterGroup->expects($this->once())->method('getFilters')->willReturn([$filter]);
     $filter->expects($this->once())->method('getConditionType')->willReturn(false);
     $filter->expects($this->once())->method('getField')->willReturn('Field');
     $filter->expects($this->atLeastOnce())->method('getValue')->willReturn('Value');
     $collection->expects($this->once())->method('addFieldToFilter')->with([['attribute' => 'Field', 'eq' => 'Value']], [['eq' => 'Value']]);
     $collection->expects($this->once())->method('getSize')->willReturn(23);
     $searchResults->expects($this->once())->method('setTotalCount')->with(23);
     $sortOrder = $this->getMock('Magento\\Framework\\Api\\SortOrder', [], [], '', false);
     $searchCriteria->expects($this->once())->method('getSortOrders')->willReturn([$sortOrder]);
     $sortOrder->expects($this->once())->method('getField')->willReturn('Field');
     $sortOrder->expects($this->once())->method('getDirection')->willReturn(\Magento\Framework\Api\SortOrder::SORT_ASC);
     $collection->expects($this->once())->method('addOrder')->with('Field', 'ASC');
     $searchCriteria->expects($this->once())->method('getCurrentPage')->willReturn(1);
     $collection->expects($this->once())->method('setCurPage')->with(1);
     $searchCriteria->expects($this->once())->method('getPageSize')->willReturn(10);
     $collection->expects($this->once())->method('setPageSize')->with(10);
     $collection->expects($this->once())->method('getItems')->willReturn([$this->address]);
     $this->address->expects($this->once())->method('getId')->willReturn(12);
     $customerAddress = $this->getMockForAbstractClass('Magento\\Customer\\Api\\Data\\AddressInterface', [], '', false);
     $this->addressRegistry->expects($this->once())->method('retrieve')->with(12)->willReturn($this->address);
     $this->address->expects($this->once())->method('getDataModel')->willReturn($customerAddress);
     $searchResults->expects($this->once())->method('setItems')->with([$customerAddress]);
     $searchResults->expects($this->once())->method('setSearchCriteria')->with($searchCriteria);
     $this->assertSame($searchResults, $this->repository->getList($searchCriteria));
 }
Пример #3
0
 /**
  * @param \Magento\Framework\Stdlib\StringUtils $string
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\ImportExport\Model\ImportFactory $importFactory
  * @param \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper
  * @param \Magento\Framework\App\ResourceConnection $resource
  * @param ProcessingErrorAggregatorInterface $errorAggregator
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\ImportExport\Model\Export\Factory $collectionFactory
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\StorageFactory $storageFactory
  * @param \Magento\Customer\Model\AddressFactory $addressFactory
  * @param \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionColFactory
  * @param \Magento\Customer\Model\CustomerFactory $customerFactory
  * @param \Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressColFactory
  * @param \Magento\Customer\Model\ResourceModel\Address\Attribute\CollectionFactory $attributesFactory
  * @param \Magento\Framework\Stdlib\DateTime $dateTime
  * @param array $data
  * @SuppressWarnings(PHPMD.NPathComplexity)
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\ImportExport\Model\ImportFactory $importFactory, \Magento\ImportExport\Model\ResourceModel\Helper $resourceHelper, \Magento\Framework\App\ResourceConnection $resource, ProcessingErrorAggregatorInterface $errorAggregator, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\ImportExport\Model\Export\Factory $collectionFactory, \Magento\Eav\Model\Config $eavConfig, \Magento\CustomerImportExport\Model\ResourceModel\Import\Customer\StorageFactory $storageFactory, \Magento\Customer\Model\AddressFactory $addressFactory, \Magento\Directory\Model\ResourceModel\Region\CollectionFactory $regionColFactory, \Magento\Customer\Model\CustomerFactory $customerFactory, \Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressColFactory, \Magento\Customer\Model\ResourceModel\Address\Attribute\CollectionFactory $attributesFactory, \Magento\Framework\Stdlib\DateTime $dateTime, array $data = [])
 {
     $this->_customerFactory = $customerFactory;
     $this->_addressFactory = $addressFactory;
     $this->_eavConfig = $eavConfig;
     $this->_resourceHelper = $resourceHelper;
     $this->dateTime = $dateTime;
     if (!isset($data['attribute_collection'])) {
         /** @var $attributeCollection \Magento\Customer\Model\ResourceModel\Address\Attribute\Collection */
         $attributeCollection = $attributesFactory->create();
         $attributeCollection->addSystemHiddenFilter()->addExcludeHiddenFrontendFilter();
         $data['attribute_collection'] = $attributeCollection;
     }
     parent::__construct($string, $scopeConfig, $importFactory, $resourceHelper, $resource, $errorAggregator, $storeManager, $collectionFactory, $eavConfig, $storageFactory, $data);
     $this->_addressCollection = isset($data['address_collection']) ? $data['address_collection'] : $addressColFactory->create();
     $this->_entityTable = isset($data['entity_table']) ? $data['entity_table'] : $addressFactory->create()->getResource()->getEntityTable();
     $this->_regionCollection = isset($data['region_collection']) ? $data['region_collection'] : $regionColFactory->create();
     $this->addMessageTemplate(self::ERROR_ADDRESS_ID_IS_EMPTY, __('Customer address id column is not specified'));
     $this->addMessageTemplate(self::ERROR_ADDRESS_NOT_FOUND, __('We can\'t find that customer address.'));
     $this->addMessageTemplate(self::ERROR_INVALID_REGION, __('Please enter a valid region.'));
     $this->addMessageTemplate(self::ERROR_DUPLICATE_PK, __('We found another row with this email, website and address ID combination.'));
     $this->_initAttributes();
     $this->_initAddresses()->_initCountryRegions();
 }
Пример #4
0
 /**
  * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  * @param \Magento\Store\Model\StoreManagerInterface $storeManager
  * @param \Magento\ImportExport\Model\Export\Factory $collectionFactory
  * @param \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory
  * @param \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate
  * @param \Magento\Eav\Model\Config $eavConfig
  * @param \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory
  * @param \Magento\CustomerImportExport\Model\Export\CustomerFactory $eavCustomerFactory
  * @param \Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressColFactory
  * @param array $data
  * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  */
 public function __construct(\Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig, \Magento\Store\Model\StoreManagerInterface $storeManager, \Magento\ImportExport\Model\Export\Factory $collectionFactory, \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory, \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate, \Magento\Eav\Model\Config $eavConfig, \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory, \Magento\CustomerImportExport\Model\Export\CustomerFactory $eavCustomerFactory, \Magento\Customer\Model\ResourceModel\Address\CollectionFactory $addressColFactory, array $data = [])
 {
     parent::__construct($scopeConfig, $storeManager, $collectionFactory, $resourceColFactory, $localeDate, $eavConfig, $data);
     $this->_customerCollection = isset($data['customer_collection']) ? $data['customer_collection'] : $customerColFactory->create();
     $this->_customerEntity = isset($data['customer_entity']) ? $data['customer_entity'] : $eavCustomerFactory->create();
     $this->_addressCollection = isset($data['address_collection']) ? $data['address_collection'] : $addressColFactory->create();
     $this->_initWebsites(true);
     $this->setFileName($this->getEntityTypeCode());
 }
Пример #5
0
 /**
  * @return \Magento\Customer\Model\ResourceModel\Address\Collection
  */
 protected function _createAddressCollection()
 {
     return $this->_addressesFactory->create();
 }