Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Customer.php
Go to the documentation of this file.
1 <?php
7 
16 class Customer extends \Magento\ImportExport\Model\Export\Entity\AbstractEav
17 {
24  const COLUMN_EMAIL = 'email';
25 
26  const COLUMN_WEBSITE = '_website';
27 
28  const COLUMN_STORE = '_store';
29 
33  const ATTRIBUTE_COLLECTION_NAME = \Magento\Customer\Model\ResourceModel\Attribute\Collection::class;
34 
38  const XML_PATH_PAGE_SIZE = 'export/customer_page_size/customer';
39 
43  protected $_attributeOverrides = [
44  'created_at' => ['backend_type' => 'datetime'],
45  'reward_update_notification' => ['source_model' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class],
46  'reward_warning_notification' => ['source_model' => \Magento\Eav\Model\Entity\Attribute\Source\Boolean::class],
47  ];
48 
54  protected $_disabledAttributes = ['default_billing', 'default_shipping'];
55 
61  protected $_indexValueAttributes = ['group_id', 'website_id', 'store_id'];
62 
69 
76 
87  public function __construct(
88  \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
89  \Magento\Store\Model\StoreManagerInterface $storeManager,
90  \Magento\ImportExport\Model\Export\Factory $collectionFactory,
91  \Magento\ImportExport\Model\ResourceModel\CollectionByPagesIteratorFactory $resourceColFactory,
92  \Magento\Framework\Stdlib\DateTime\TimezoneInterface $localeDate,
93  \Magento\Eav\Model\Config $eavConfig,
94  \Magento\Customer\Model\ResourceModel\Customer\CollectionFactory $customerColFactory,
95  array $data = []
96  ) {
97  parent::__construct(
98  $scopeConfig,
100  $collectionFactory,
101  $resourceColFactory,
102  $localeDate,
103  $eavConfig,
104  $data
105  );
106 
107  $this->_customerCollection = isset(
108  $data['customer_collection']
109  ) ? $data['customer_collection'] : $customerColFactory->create();
110 
111  $this->_initAttributeValues()->_initAttributeTypes()->_initStores()->_initWebsites(true);
112  }
113 
119  public function export()
120  {
122  $writer = $this->getWriter();
123 
124  // create export file
125  $writer->setHeaderCols($this->_getHeaderColumns());
127 
128  return $writer->getContents();
129  }
130 
136  protected function _getEntityCollection()
137  {
139  }
140 
144  protected function _getHeaderColumns()
145  {
146  $validAttributeCodes = $this->_getExportAttributeCodes();
147  return array_merge($this->_permanentAttributes, $validAttributeCodes, ['password']);
148  }
149 
156  public function exportItem($item)
157  {
159  $row[self::COLUMN_WEBSITE] = $this->_websiteIdToCode[$item->getWebsiteId()];
160  $row[self::COLUMN_STORE] = $this->_storeIdToCode[$item->getStoreId()];
161 
162  $this->getWriter()->writeRow($row);
163  }
164 
171  public function filterAttributeCollection(\Magento\Framework\Data\Collection $collection)
172  {
174  foreach (parent::filterAttributeCollection($collection) as $attribute) {
175  if (!empty($this->_attributeOverrides[$attribute->getAttributeCode()])) {
176  $data = $this->_attributeOverrides[$attribute->getAttributeCode()];
177 
178  if (isset($data['options_method']) && method_exists($this, $data['options_method'])) {
179  $data['filter_options'] = $this->{$data['options_method']}();
180  }
181  $attribute->addData($data);
182  }
183  }
184  return $collection;
185  }
186 
192  public function getEntityTypeCode()
193  {
194  return $this->getAttributeCollection()->getEntityTypeCode();
195  }
196 
202  public function getOverriddenAttributes()
203  {
205  }
206 }
__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, array $data=[])
Definition: Customer.php:87
$storeManager
_prepareEntityCollection(AbstractCollection $collection)
_addAttributeValuesToRow(\Magento\Framework\Model\AbstractModel $item, array $row=[])
_exportCollectionByPages(\Magento\Framework\Data\Collection\AbstractDb $collection)