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 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156
<?php
/* --------------------------------------------------------------
CustomerGroupWriter.inc.php 2017-09-06
Gambio GmbH
http://www.gambio.de
Copyright (c) 2017 Gambio GmbH
Released under the GNU General Public License (Version 2)
[http://www.gnu.org/licenses/gpl-2.0.html]
--------------------------------------------------------------
*/
/**
* Class CustomerGroupWriter
*
* @category System
* @package CustomerGroup
* @subpackage Repositories
*/
class CustomerGroupWriter implements CustomerGroupWriterInterface
{
/**
* @var \CI_DB_query_builder
*/
protected $queryBuilder;
/**
* @var \LanguageProvider
*/
protected $languageProvider;
/**
* CustomerGroupWriter constructor.
*
* @param \CI_DB_query_builder $queryBuilder
* @param \LanguageProvider $languageProvider
*/
public function __construct(CI_DB_query_builder $queryBuilder, LanguageProvider $languageProvider)
{
$this->queryBuilder = $queryBuilder;
$this->languageProvider = $languageProvider;
}
/**
* Saves customer group entity data in database.
*
* @param \CustomerGroupInterface $customerGroup Customer group to be saved.
*
* @return $this|\CustomerGroupWriterInterface Same instance for chained method calls.
*/
public function store(CustomerGroupInterface $customerGroup)
{
$lastCustomerGroupId = $this->queryBuilder->select('customers_status_id')
->from('customers_status')
->order_by('customers_status_id', 'DESC')
->get()
->row_array()['customers_status_id'];
$customerGroupId = (int)$lastCustomerGroupId + 1;
if(count($customerGroup->getNames()) > 0)
{
foreach($customerGroup->getNames() as $languageCode => $name)
{
$this->queryBuilder->set([
'customers_status_id' => $customerGroupId,
'language_id' => $this->languageProvider->getIdByCode(MainFactory::create('LanguageCode',
new StringType($languageCode))),
'customers_status_name' => $name,
'customers_status_public' => $customerGroup->getSettings()
->isPublic(),
'customers_status_min_order' => $customerGroup->getConfigurations()
->getMinOrder(),
'customers_status_max_order' => $customerGroup->getConfigurations()
->getMaxOrder(),
'customers_status_discount' => $customerGroup->getConfigurations()
->getDiscount(),
'customers_status_ot_discount_flag' => $customerGroup->getSettings()
->isOtDiscountFlag(),
'customers_status_ot_discount' => $customerGroup->getConfigurations()
->getOtDiscount(),
'customers_status_graduated_prices' => $customerGroup->getSettings()
->isGraduatedPrices(),
'customers_status_show_price' => $customerGroup->getSettings()
->isShowPrice(),
'customers_status_show_price_tax' => $customerGroup->getSettings()
->isShowPriceTax(),
'customers_status_add_tax_ot' => $customerGroup->getSettings()
->isAddTaxOt(),
'customers_status_payment_unallowed' => implode(',',$customerGroup->getConfigurations()
->getUnallowedPaymentModules()),
'customers_status_shipping_unallowed' => implode(',',$customerGroup->getConfigurations()
->getUnallowedShippingModules()),
'customers_status_discount_attributes' => $customerGroup->getSettings()
->isDiscountAttributes(),
'customers_fsk18' => $customerGroup->getSettings()
->isFsk18(),
'customers_fsk18_display' => $customerGroup->getSettings()
->isFsk18Display(),
'customers_status_write_reviews' => $customerGroup->getSettings()
->isWriteReviews(),
'customers_status_read_reviews' => $customerGroup->getSettings()
->isReadReviews()
]);
$this->queryBuilder->insert('customers_status');
}
}
$customerGroup->setId(new IntType($customerGroupId));
return $this;
}
/**
* Updates customer group entity data in database.
*
* @param \CustomerGroupInterface $customerGroup Customer group to be updated.
*
* @return $this|\CustomerGroupWriterInterface Same instance for chained method calls.
*/
public function update(CustomerGroupInterface $customerGroup)
{
foreach($customerGroup->getNames() as $languageCode => $name)
{
$languageId = $this->languageProvider->getIdByCode(new LanguageCode(new StringType($languageCode)));
$this->queryBuilder->update('customers_status', [
'customers_status_name' => $name,
'customers_status_public' => $customerGroup->getSettings()->isPublic(),
'customers_status_min_order' => $customerGroup->getConfigurations()->getMinOrder(),
'customers_status_max_order' => $customerGroup->getConfigurations()->getMaxOrder(),
'customers_status_discount' => $customerGroup->getConfigurations()->getDiscount(),
'customers_status_ot_discount_flag' => $customerGroup->getSettings()->isOtDiscountFlag(),
'customers_status_ot_discount' => $customerGroup->getConfigurations()->getOtDiscount(),
'customers_status_graduated_prices' => $customerGroup->getSettings()->isGraduatedPrices(),
'customers_status_show_price' => $customerGroup->getSettings()->isShowPrice(),
'customers_status_show_price_tax' => $customerGroup->getSettings()->isShowPriceTax(),
'customers_status_add_tax_ot' => $customerGroup->getSettings()->isAddTaxOt(),
'customers_status_payment_unallowed' => implode(',', $customerGroup->getConfigurations()
->getUnallowedPaymentModules()),
'customers_status_shipping_unallowed' => implode(',', $customerGroup->getConfigurations()
->getUnallowedShippingModules()),
'customers_status_discount_attributes' => $customerGroup->getSettings()->isDiscountAttributes(),
'customers_fsk18' => $customerGroup->getSettings()->isFsk18(),
'customers_fsk18_display' => $customerGroup->getSettings()->isFsk18Display(),
'customers_status_write_reviews' => $customerGroup->getSettings()->isWriteReviews(),
'customers_status_read_reviews' => $customerGroup->getSettings()->isReadReviews()
], ['customers_status_id' => $customerGroup->getId(), 'language_id' => $languageId]);
}
return $this;
}
}