1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
<?php
class CustomerGroupReader implements CustomerGroupReaderInterface
{
protected $queryBuilder;
public function __construct(CI_DB_query_builder $queryBuilder)
{
$this->queryBuilder = $queryBuilder;
}
public function getAll()
{
$rawData = $this->queryBuilder->get('customers_status')->result_array() ? : [];
$resultData = [];
$customerGroups = [];
foreach($rawData as $data)
{
if(isset($oldId) && $oldId !== (int)$data['customers_status_id'])
{
$resultData[] = $customerGroups;
$customerGroups = [];
}
$oldId = (int)$data['customers_status_id'];
$customerGroups['id'] = $oldId;
$customerGroups['names'][$data['language_id']] = $data['customers_status_name'];
$customerGroups['settings'] = $this->_getSettingsData($data);
$customerGroups['configurations'] = $this->_getConfigurationsData($data);
}
if(count($rawData) > 0)
{
$resultData[] = $customerGroups;
}
return $resultData;
}
public function getById(IntType $id)
{
$rawData = $this->queryBuilder->select()
->from('customers_status')
->where('customers_status_id', $id->asInt())
->get()
->result_array() ? : [];
if(count($rawData) === 0)
{
throw new EntityNotFoundException('Customer group entity was not found with provided id "' . $id->asInt()
. '"');
}
$result = ['id' => $id->asInt()];
$customerGroupsNames = [];
foreach($rawData as $data)
{
$customerGroupsNames[$data['language_id']] = $data['customers_status_name'];
$result['settings'] = $this->_getSettingsData($data);
$result['configurations'] = $this->_getConfigurationsData($data);
}
$result['names'] = $customerGroupsNames;
return $result;
}
private function _getSettingsData(array $customerGroupData)
{
return [
'public' => (int)$customerGroupData['customers_status_public'] === 1,
'otDiscount' => (int)$customerGroupData['customers_status_ot_discount_flag'] === 1,
'graduatedPrices' => (int)$customerGroupData['customers_status_graduated_prices'] === 1,
'showPrice' => (int)$customerGroupData['customers_status_show_price'] === 1,
'showPriceTax' => (int)$customerGroupData['customers_status_show_price_tax'] === 1,
'addTaxOt' => (int)$customerGroupData['customers_status_add_tax_ot'] === 1,
'discountAttributes' => (int)$customerGroupData['customers_status_discount_attributes'] === 1,
'fsk18' => (int)$customerGroupData['customers_fsk18'] === 1,
'fsk18Display' => (int)$customerGroupData['customers_fsk18_display'] === 1,
'writeReviews' => (int)$customerGroupData['customers_status_write_reviews'] === 1,
'readReviews' => (int)$customerGroupData['customers_status_read_reviews'] === 1,
];
}
private function _getConfigurationsData(array $customerGroupData)
{
return [
'minOrder' => $customerGroupData['customers_status_min_order'] ? (double)$customerGroupData['customers_status_min_order'] : null,
'maxOrder' => $customerGroupData['customers_status_max_order'] ? (double)$customerGroupData['customers_status_max_order'] : null,
'discount' => $customerGroupData['customers_status_discount'] ? (double)$customerGroupData['customers_status_discount'] : null,
'otDiscount' => $customerGroupData['customers_status_ot_discount'] ? (double)$customerGroupData['customers_status_ot_discount'] : null,
'unallowedPaymentModules' => $customerGroupData['customers_status_payment_unallowed'] !== '' ? explode(',',
$customerGroupData['customers_status_payment_unallowed']) : [],
'unallowedShippingModules' => $customerGroupData['customers_status_payment_unallowed'] !== '' ? explode(',',
$customerGroupData['customers_status_shipping_unallowed']) : [],
];
}
}