예제 #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;
 }
예제 #2
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();
 }
예제 #3
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());
 }
예제 #4
0
 /**
  * @return \Magento\Customer\Model\ResourceModel\Address\Collection
  */
 protected function _createAddressCollection()
 {
     return $this->_addressesFactory->create();
 }