Example #1
0
 /**
  * Get All products from catalog
  *
  * @param int|null $mage_store_id
  * @param string|null $updated_at_min
  * @param string|null $updated_at_max
  * @param int|null $limit
  * @param int|null $page
  * @param int|null $since_id
  * @param int|null $customer_id
  * @return array $customerData
  */
 public function getCustomers($mage_store_id, $updated_at_min = null, $updated_at_max = null, $limit = null, $page = null, $since_id = null, $customer_id = null)
 {
     $pageNumber = null;
     $pageSize = null;
     $customerData = $this->_customerCollectionFactory->create();
     if ($customer_id !== null) {
         $customerData->addFieldToFilter('entity_id', $customer_id);
     }
     $customerData->addFieldToFilter('store_id', ['eq' => $mage_store_id]);
     //$mage_store_id));
     if ($updated_at_min != null) {
         $customerData->addAttributeToFilter('updated_at', ['gt' => $updated_at_min]);
     }
     if ($updated_at_max != null) {
         $customerData->addAttributeToFilter('updated_at', ['lt' => $updated_at_max]);
     }
     if ($since_id != null) {
         $customerData->addAttributeToFilter('entity_id', ['gt' => $since_id]);
     }
     if ($limit != null) {
         $pageNumber = 1;
         // Note that page numbers begin at 1 in Magento
         $pageSize = $limit;
     }
     if ($page != null) {
         if (!is_null($pageSize)) {
             $pageNumber = $page + 1;
             // Note that page numbers begin at 1 in Magento
         }
     }
     if (!is_null($pageSize)) {
         $customerData->setPage($pageNumber, $pageSize);
     }
     $customerArray = [];
     $map = $this->response_mask;
     foreach ($customerData as $customer) {
         $customers = [];
         $mappedCustomer = $customer->getData();
         $newsletter = $this->subscriber->load($customer->getId(), 'customer_id');
         foreach ($map['customers'] as $element => $value) {
             $mappedCustomer['id'] = $customer->getId();
             if (!is_array($value)) {
                 if (array_key_exists($value, $mappedCustomer)) {
                     if ($element == 'gender' && $mappedCustomer['gender'] == '0') {
                         $mappedCustomer['gender'] = 'Not Selected';
                     }
                     if ($element == 'gender' && $mappedCustomer['gender'] == '1') {
                         $mappedCustomer['gender'] = 'M';
                     }
                     if ($element == 'gender' && $mappedCustomer['gender'] == '2') {
                         $mappedCustomer['gender'] = 'F';
                     }
                     $customers[$element] = $mappedCustomer[$value];
                 }
             }
         }
         $customers['default_address'] = $this->getCustomerAddresses($customer->getId());
         $group = $this->customerGroupFactory->load($customer->getGroupId());
         $customers['groups'] = array();
         $customers['groups'][] = ['id' => $group->getId(), 'name' => $group->getCustomerGroupCode()];
         if ($newsletter->isSubscribed()) {
             $customers['accepts_marketing'] = 'true';
         } else {
             $customers['accepts_marketing'] = 'false';
         }
         $customerArray[] = $customers;
     }
     $object = new DataObject();
     $object->setCustomers($customerArray);
     return $object;
 }