1: <?php
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: class dpdcodpayment extends PaymentModule {
42:
43: 44: 45: 46:
47: public $ver = '1.6';
48:
49: 50: 51: 52:
53: protected $_title;
54:
55: 56: 57: 58:
59: protected $_info_text;
60:
61: 62: 63: 64:
65: protected $_checkstore;
66:
67: 68: 69: 70:
71: protected $_store_scope;
72:
73:
74: 75: 76: 77:
78: protected $_config_prefix = 'EABI_DPDCOD_';
79: const CONST_PREFIX = 'EABI_DPDCOD_';
80:
81: 82: 83: 84:
85: protected $_config_array = array(
86:
87: 'TITLE',
88:
89: 'INFO_TEXT',
90:
91: 'ORDER_STATUS',
92:
93: 'SEND_STATUS',
94:
95: 'CHECKSTORE',
96: );
97:
98: 99: 100: 101:
102: protected $form_fields = array();
103:
104:
105: 106: 107: 108:
109: protected static $_helperModuleInstance;
110:
111: 112: 113: 114:
115: protected $_id_store;
116:
117: 118: 119: 120:
121: protected $_id_store_group;
122:
123:
124:
125:
126: 127: 128:
129: public function __construct() {
130: if (substr(_PS_VERSION_, 0, 3) == "1.5") {
131: $this->ver = "1.5";
132: }
133: $this->name = 'dpdcodpayment';
134: $this->tab = 'payments_gateways';
135:
136: $this->version = '0.9';
137: $this->secure_key = Tools::encrypt($this->name);
138: $this->bootstrap = false;
139:
140: $this->currencies = true;
141: $this->currencies_mode = 'checkbox';
142: $this->dependencies[] = 'eabi_dpd_parcelstore';
143: $this->ps_versions_compliancy = array('min' => '1.5', 'max' => '1.7');
144:
145:
146: $cookie = new Cookie('psAdmin');
147: if ($cookie->id_employee) {
148: $this->_id_store_group = Tools::getValue('id_store_group', '0');
149: $this->_id_store = Tools::getValue('id_store', '0');
150:
151: }
152:
153: $config = Configuration::getMultiple($this->_getConfigArray($this->_config_prefix, $this->_config_array)
154: , null
155: , $this->_id_store_group
156: , $this->_id_store);
157: $this->_initConfig($config);
158:
159: parent::__construct();
160:
161: $this->displayName = $this->l('Cash on delivery for DPD');
162: $this->description = $this->l('Allows customers to pay for the order at the moment when customer receives the package. Requires contractual relationships with DPD');
163: $this->confirmUninstall = $this->l('Are you sure you want to delete your details?');
164: if (!isset($this->_title) || !isset($this->_order_status) || !isset($this->_checkstore)) {
165:
166: $this->warning = $this->l('Details must be configured in order to use this module correctly');
167: }
168: if (!sizeof(Currency::checkPaymentCurrencies($this->id))) {
169: $this->warning = $this->l('No currency set for this module');
170: }
171: }
172:
173: 174: 175: 176: 177: 178: 179: 180: 181: 182: 183:
184: public function install() {
185: if (!parent::install() || !$this->registerHook('payment') || !$this->registerHook('paymentReturn')
186: || !$this->registerHook('actionValidateOrder') || !$this->registerHook('displayHeader')
187: || !$this->upgrade_module_0_6()) {
188: return false;
189: }
190: return true;
191:
192: }
193:
194: 195: 196: 197: 198: 199: 200: 201: 202: 203: 204:
205: public function uninstall() {
206:
207: 208: 209: 210: 211: 212: 213: 214: 215:
216: if (!$this->unregisterHook('payment') || !$this->unregisterHook('paymentReturn')
217: || !$this->unregisterHook('actionValidateOrder')
218: || !$this->unregisterHook('displayHeader')
219: || $this->unregisterHook('actionOrderStatusPostUpdate')) {
220:
221: }
222: if (!parent::uninstall()) {
223: return false;
224: }
225: return true;
226: }
227:
228:
229:
230:
231:
232:
233: 234: 235: 236:
237: public function getContent() {
238: $html = '<h2>' . $this->displayName . '</h2>';
239:
240: if (!empty($_POST)) {
241: $postErrors = $this->_postValidation();
242: if (!sizeof($postErrors)) {
243: $html .= $this->_postProcess();
244: } else {
245: foreach ($postErrors as $err) {
246: $html .= '<div class="alert error">' . $err . '</div>';
247: }
248: }
249: } else {
250: $html .= '<br />';
251: }
252:
253: $html .= $this->_displayHeader();
254: $html .= $this->_displayForm();
255:
256: return $html;
257: }
258:
259:
260: 261: 262: 263: 264: 265: 266: 267: 268: 269: 270:
271: public function execPayment($cart) {
272: $params = array('cart' => $cart);
273: if (!$this->_isAvailable($params)) {
274: return;
275: }
276:
277: $cookie = Context::getContext()->cookie;
278: $smarty = Context::getContext()->smarty;
279:
280: $curr = new Currency($cart->id_currency);
281: $module = array(
282: '_title' => $this->getCurrentLangValue($this->_title),
283: '_extra' => $this->getTitle($params['cart']),
284: '_text' => $this->getCurrentLangValue($this->_info_text),
285: );
286:
287:
288: $smarty->assign(array(
289: 'nbProducts' => $cart->nbProducts(),
290: 'cust_currency' => $cookie->id_currency,
291: 'currencies' => $this->getCurrency(),
292: 'total' => number_format($cart->getOrderTotal(true, 3) / $curr->conversion_rate, 2, '.', ''),
293: 'isoCode' => Language::getIsoById(intval($cookie->id_lang)),
294: 'this_path' => $this->_path,
295: 'current_module' => $module,
296: 'this_path_ssl' => (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . htmlspecialchars($_SERVER['HTTP_HOST'], ENT_COMPAT, 'UTF-8') . __PS_BASE_URI__ . 'modules/' . $this->name . '/'
297: ));
298: if ($this->ver == "1.5") {
299: return $this->display(__FILE__, 'payment_exec.tpl');
300: }
301: return $this->display(__FILE__, 'payment_execution.tpl');
302: }
303:
304:
305: 306: 307: 308: 309: 310: 311:
312: public function hookPayment($params) {
313: if (!$this->_isAvailable($params)) {
314: return;
315: }
316:
317: $smarty = Context::getContext()->smarty;
318:
319:
320: $module = array(
321: '_title' => $this->getCurrentLangValue($this->_title),
322: '_extra' => $this->getTitle($params['cart']),
323: '_text' => $this->getCurrentLangValue($this->_info_text),
324: );
325:
326: $smarty->assign(array(
327: 'this_path' => $this->_path,
328: 'this_path_ssl' => Tools::getShopDomainSsl(true, true) . __PS_BASE_URI__ . 'modules/' . $this->name . '/',
329: 'title' => htmlspecialchars($this->l($this->_title)),
330: 'description' => htmlspecialchars($this->l($this->_info_text)),
331: 'current_module' => $module,
332: ));
333:
334: if ($this->ver == "1.5") {
335: return $this->display(__FILE__, 'payment_15.tpl');
336: } else {
337: return $this->display(__FILE__, 'payment.tpl');
338: }
339: }
340:
341:
342: 343: 344: 345: 346: 347: 348: 349: 350: 351:
352: public function hookActionValidateOrder($params) {
353: }
354:
355: 356: 357: 358:
359: public function ($params) {
360: $this->context->controller->addCSS($this->_path . $this->name . '.css', 'all');
361: }
362:
363: 364: 365: 366: 367: 368:
369: public function isAvailable($params) {
370: return $this->_isAvailable($params);
371: }
372:
373:
374:
375:
376: 377: 378: 379: 380: 381:
382: public function getCodFee($cart) {
383: $convertedCodFee = false;
384: if ($cart && $cart->id_carrier) {
385:
386:
387: $carrierInstance = $this->_getHelperModule()->getCarrierInstanceFromIdCarrier($cart->id_carrier);
388: $address = new Address($this->_getIdAddress($cart));
389: $codFee = $carrierInstance->getCodFee($address, $cart);
390: $currency = Currency::getCurrencyInstance($cart->id_currency);
391: $convertedCodFee = Tools::convertPrice($codFee, $currency);
392: }
393: return $convertedCodFee;
394: }
395:
396: 397: 398: 399:
400: public function getTitle($cart) {
401: $carrierInstance = null;
402: $finalFee = false;
403: $title = '';
404: $convertedCodFee = $this->getCodFee($cart);
405:
406:
407: if ($convertedCodFee) {
408: $currency = Currency::getCurrencyInstance($cart->id_currency);
409: $finalFee = Tools::displayPrice($convertedCodFee, $currency);
410:
411: return $title . ' (' . $finalFee . ' ' . $this->l('Will be added to shipping fee').')';
412: }
413: return $title;
414: }
415:
416:
417:
418:
419:
420: 421: 422: 423: 424: 425: 426: 427: 428:
429: public function hookActionOrderStatusPostUpdate($params) {
430: if ($params && isset($params['newOrderStatus']) && $params['newOrderStatus']) {
431: if ($params['newOrderStatus']->id == $this->getConfigData('SEND_STATUS')) {
432: $order = new OrderCore($params['id_order']);
433:
434:
435:
436: $carrierInstance = $this->_getHelperModule()->getCarrierInstanceFromIdCarrier($order->id_carrier)
437: ;
438: if ($carrierInstance && method_exists($carrierInstance, 'isCodEnabled')) {
439: $params['is_eabi_dpd_cod'] = true;
440: $carrierInstance->hookPaymentConfirm($params);
441: }
442: }
443: }
444: }
445:
446: 447: 448: 449: 450:
451: public function getCurrentLangValue($title) {
452: $finalTitle = $title;
453: if ($this->_isSerialized($title)) {
454: $title = @unserialize($title);
455: if (is_array($title)) {
456: $finalTitle = isset($title[$this->context->language->id]) ? $title[$this->context->language->id] : $title[0];
457: }
458: }
459: return $finalTitle;
460:
461: }
462:
463:
464:
465:
466:
467: 468: 469: 470: 471:
472: public function checkCurrency($cart) {
473: $currency_order = new Currency($cart->id_currency);
474: $currencies_module = $this->getCurrency($cart->id_currency);
475:
476: if (is_array($currencies_module)) {
477: foreach ($currencies_module as $currency_module) {
478: if ($currency_order->id == $currency_module['id_currency']) {
479: return true;
480: }
481: }
482: }
483: return false;
484: }
485:
486: 487: 488: 489: 490:
491: public function addCheckboxCurrencyRestrictionsForModule(array $shops = array()) {
492: if (!$shops)
493: $shops = Shop::getShops(true, null, true);
494:
495: foreach ($shops as $s) {
496: if (!Db::getInstance()->execute('
497: INSERT INTO `' . _DB_PREFIX_ . 'module_currency` (`id_module`, `id_shop`, `id_currency`)
498: SELECT ' . (int) $this->id . ', "' . (int) $s . '", `id_currency` FROM `' . _DB_PREFIX_ . 'currency` WHERE deleted = 0 and iso_code = \'EUR\''))
499: return false;
500: }
501: return true;
502: }
503:
504: 505: 506: 507: 508:
509: public function addCheckboxCountryRestrictionsForModule(array $shops = array()) {
510: $countries = Country::getCountries((int) Context::getContext()->language->id, true);
511: $allowedCountries = array(
512: 'EE', 'LV', 'LT',
513: );
514: $country_ids = array();
515: foreach ($countries as $country) {
516: if (in_array($country['iso_code'], $allowedCountries)) {
517: $country_ids[] = $country['id_country'];
518: }
519: }
520: return Country::addModuleRestrictions($shops, $countries, array(array('id_module' => (int) $this->id)));
521: }
522:
523:
524:
525: 526: 527: 528: 529:
530: public function getConfigData($param) {
531:
532: $value = Configuration::get(self::CONST_PREFIX . $param);
533: if ($value === null || $value === false) {
534: $formFields = $this->_initFormFields();
535: if (isset($formFields[strtolower($param)]) && $formFields[strtolower($param)]['default']) {
536: return $formFields[strtolower($param)]['default'];
537: }
538: }
539: return $value;
540: }
541: 542: 543: 544: 545:
546: public function getFormConfigData($param) {
547:
548: $value = Configuration::get(self::CONST_PREFIX . $param, null, $this->_id_store_group, $this->_id_store);
549: if ($value === null || $value === false) {
550: $formFields = $this->_initFormFields();
551: if (isset($formFields[strtolower($param)]) && $formFields[strtolower($param)]['default']) {
552: return $formFields[strtolower($param)]['default'];
553: }
554: }
555: return $value;
556: }
557:
558: 559: 560: 561:
562: public function _getHelperModule() {
563: if (is_null(self::$_helperModuleInstance)) {
564: self::$_helperModuleInstance = Module::getInstanceByName('eabi_postoffice');
565: }
566: return self::$_helperModuleInstance;
567: }
568:
569:
570: 571: 572: 573: 574:
575: public function getGlobalConfigData($param) {
576: $value = Configuration::getGlobalValue(self::CONST_PREFIX . $param);
577: if ($value === null || $value === false) {
578: $formFields = $this->_initFormFields();
579: if (isset($formFields[strtolower($param)]) && $formFields[strtolower($param)]['default']) {
580: return $formFields[strtolower($param)]['default'];
581: }
582: }
583: return $value;
584: }
585:
586: 587: 588: 589:
590: protected function _postValidation() {
591: $errors = array();
592: if (strtoupper($_SERVER['REQUEST_METHOD']) != 'POST') {
593:
594: return $errors;
595: }
596: foreach ($this->_initFormFields() as $formFieldName => $formFieldData) {
597: $validationRules = isset($formFieldData['validate']) ? $formFieldData['validate'] : array();
598: $validationIfRules = isset($formFieldData['validate-if']) ? $formFieldData['validate-if'] : array();
599:
600: $selectValidationResult = $this->_getValidator()->validate('validate_select', strtoupper($formFieldName), $_POST, $validationIfRules, $formFieldData);
601: if (is_string($selectValidationResult)) {
602:
603: $errors[] = sprintf($selectValidationResult, $formFieldData['title']);
604: break;
605: }
606:
607: foreach ($validationRules as $validationRule) {
608: $validationResult = $this->_getValidator()->validate($validationRule, strtoupper($formFieldName), $_POST, $validationIfRules, $formFieldData);
609: if (is_string($validationResult)) {
610:
611: $errors[] = sprintf($this->l($validationResult), $formFieldData['title']);
612: break;
613: }
614: }
615: }
616:
617:
618: return $errors;
619: }
620:
621:
622:
623:
624:
625: 626: 627: 628: 629: 630: 631:
632: protected function _getFormHtml($action, $method, $formFields) {
633: $action = Tools::htmlentitiesUTF8($action);
634: $html = '';
635:
636: $formElementsHtml = '';
637: $formElementHelper = $this->_getHtmlHelper();
638: foreach ($formFields as $fieldName => $fieldData) {
639: $methodName = 'get' . ucfirst($fieldData['type']) . 'Html';
640: $fieldPropertyName = '_' . $fieldName;
641: $value = Tools::getValue(strtoupper($fieldName), $this->getFormConfigData(strtoupper($fieldName)));
642:
643:
644: if ($this->_id_store || $this->_id_store_group) {
645: $fieldData['global_value'] = $this->getGlobalConfigData(strtoupper($fieldName));
646: }
647:
648:
649: if (method_exists($formElementHelper, $methodName)) {
650: $formElementsHtml .= $formElementHelper->$methodName(strtoupper($fieldName), $fieldData, $value);
651: } else {
652: $formElementsHtml .= $formElementHelper->getTextHtml(strtoupper($fieldName), $fieldData, $value);
653: }
654: }
655:
656: $formClass = 'eabi_dpd_parcelstore '.$this->name;
657:
658: $html .= <<<HTML
659: <form action="{$action}" method="{$method}">
660: <fieldset>
661: <legend><img src="../img/admin/contact.gif" alt="" />{$this->l('Configuration details')}</legend>
662: <table id="form" class="{$formClass}">
663: <colgroup class="label"></colgroup>
664: <colgroup class="value"></colgroup>
665: <tbody>
666: {$formElementsHtml}
667: <tr>
668: <td colspan="2"><input class="button" name="btnSubmit" value="{$this->l('Update settings')}" type="submit" /></td>
669: </tr>
670: </tbody>
671: </table>
672: </fieldset>
673: </form>
674: HTML;
675: return $html;
676: }
677:
678: 679: 680: 681: 682: 683: 684: 685: 686: 687: 688: 689:
690: protected function _isAvailable($params) {
691:
692: $cart = $params['cart'];
693: if (!$this->active) {
694: return false;
695: }
696: if (!$this->checkCurrency($cart)) {
697: return false;
698: }
699: if ($cart && $cart->id_carrier) {
700:
701: if ($this->getConfigData('CHECKSTORE') == 'yes' && !$cart->isAllProductsInStock(true)) {
702:
703: return false;
704: }
705:
706:
707: $carrierInstance = $this->_getHelperModule()->getCarrierInstanceFromIdCarrier($cart->id_carrier);
708: if ($carrierInstance && method_exists($carrierInstance, 'getCodFee')
709: && method_exists($carrierInstance, 'isCodEnabled') && $carrierInstance->isCodEnabled(new Address($this->_getIdAddress($cart)))) {
710:
711:
712: return true;
713: }
714:
715: } else {
716: return false;
717: }
718:
719: return false;
720: }
721:
722: 723: 724: 725: 726: 727:
728: protected function _getIdAddress($cart) {
729:
730:
731: $origIdAddress = $cart->id_address_delivery;
732: $products = $cart->getProducts();
733: foreach ($products as $product) {
734: if (!$product['is_virtual']) {
735: if ($product['id_address_delivery'] != $origIdAddress && $product['id_address_delivery']) {
736: $origIdAddress = $product['id_address_delivery'];
737: }
738: break;
739: }
740: }
741:
742:
743: return $origIdAddress;
744: }
745:
746:
747: 748: 749: 750: 751:
752: protected function _isSerialized($input) {
753: return preg_match('/^([adObis]):/', $input);
754: }
755:
756: 757: 758: 759:
760: protected function _getHtmlHelper() {
761:
762: $helper = $this->_getHelperModule()->helper('html_helper', eabi_dpd_parcelstore::NAME);
763: $helper->setContext($this->context)->setModuleInstance($this);
764: return $helper;
765: }
766:
767: 768: 769: 770:
771: protected function _getValidator() {
772: return $this->_getHelperModule()->helper('validator_helper', eabi_dpd_parcelstore::NAME);
773: }
774:
775:
776:
777:
778:
779:
780:
781: 782: 783: 784:
785: private function _postProcess() {
786: $data = $_POST;
787: $html = '';
788: if (isset($data['btnSubmit'])) {
789: $config = $this->_getConfigArray('', $this->_config_array);
790:
791:
792:
793: foreach ($config as $configValue) {
794: if (is_array($data[$configValue])) {
795: $data[$configValue] = serialize($data[$configValue]);
796: }
797:
798:
799:
800: Configuration::updateValue($this->_config_prefix . $configValue, $data[$configValue], false
801: , Tools::getValue('id_store_group', '0')
802: , Tools::getValue('id_store', '0'));
803:
804: }
805: $config = Configuration::getMultiple($this->_getConfigArray($this->_config_prefix, $this->_config_array));
806: $this->_initConfig($config);
807:
808: $html .= '<div class="conf confirm"><img src="../img/admin/ok.gif" alt="' . $this->l('ok') . '" /> ' . $this->l('Settings updated') . '</div>';
809: }
810: return $html;
811: }
812:
813:
814: 815: 816: 817:
818: private function () {
819: $html = <<<HTML
820: <img src="../modules/{$this->name}/{$this->name}.gif" alt="" style="float:left; margin-right:15px;"/>
821: <b>{$this->l('This module allows you to accept COD payments from customers using DPD services')}</b>
822: <br />{$this->l('COD delivery fee can be set under DPD own settings')}
823: <br />
824: <br />
825: <br />
826: <br />
827: HTML;
828:
829: return $html;
830: }
831:
832: 833: 834: 835:
836: private function _displayForm() {
837:
838: if (Configuration::getGlobalValue('PS_MULTISHOP_FEATURE_ACTIVE')) {
839: $shopFields = array(
840: 'store_scope' => array(
841: 'title' => $this->l('Store Scope'),
842: 'type' => 'stores',
843: 'description' => $this->l('Current configuration scope'),
844: 'default' => '0',
845: 'css' => 'width: 300px;',
846: )
847: );
848: $formFields = array_merge($shopFields, $this->_initFormFields());
849: } else {
850: $formFields = $this->_initFormFields();
851: }
852:
853:
854: $html = $this->_getFormHtml($_SERVER['REQUEST_URI'], 'post', $formFields);
855: return $html;
856: }
857:
858:
859: 860: 861: 862: 863:
864: private function _initFormFields() {
865: if (count($this->form_fields)) {
866: return $this->form_fields;
867: }
868: $returnUri = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . $_SERVER['HTTP_HOST'] . __PS_BASE_URI__ . 'modules/' . $this->name . '/validatePayment.php';
869:
870:
871: if ((int) Tools::getValue('id_store', 0)) {
872: $shop = new Shop((int) Tools::getValue('id_store', 0));
873: $urls = $shop->getUrls();
874: if (isset($urls[0])) {
875: $returnUri = (Configuration::get('PS_SSL_ENABLED') ? 'https://' : 'http://') . $urls[0]['domain_ssl'] . $urls[0]['physical_uri'] . 'modules/' . $this->name . '/validatePayment.php';
876: }
877: }
878: $yesno = array(
879: 'yes' => $this->l('Yes'),
880: 'no' => $this->l('No'),
881: );
882:
883: $orderStates = OrderState::getOrderStates((int)Context::getContext()->language->id);
884:
885: $orderStatuses = array();
886: foreach ($orderStates as $orderState) {
887: $orderStatuses[(string)$orderState['id_order_state']] = $orderState['name'];
888: }
889:
890:
891: $this->form_fields = array(
892: 'title' => array(
893: 'title' => $this->l('Text displayed to client'),
894: 'type' => 'multilang',
895: 'description' => $this->l('This controls the title which the user sees during checkout.'),
896: 'default' => 'Tasun lunaga paki kättesaamisel',
897: 'css' => 'width: 300px;',
898: ),
899: 'info_text' => array(
900: 'title' => $this->l('Description displayed to the client'),
901: 'type' => 'multilangtextarea',
902: 'description' => $this->l('This controls the description which the user sees during checkout.'),
903: 'default' => '',
904: 'css' => 'width: 300px;',
905: ),
906: 'order_status' => array(
907: 'title' => $this->l('New order status'),
908: 'type' => 'select',
909: 'default' => Configuration::get('PS_OS_BANKWIRE'),
910: 'options' => $orderStatuses,
911: 'css' => 'width: 300px;',
912: ),
913: 'send_status' => array(
914: 'title' => $this->l('Order status for initiating data sending without marking order as paid.'),
915: 'type' => 'select',
916: 'default' => '',
917: 'options' => $orderStatuses,
918: 'description' => $this->l('If you want to send data to DPD server without marking order as paid, you need to set order to this status.'),
919: 'css' => 'width: 300px;',
920: ),
921: 'checkstore' => array(
922: 'title' => $this->l('Allow only for products which are in-stock'),
923: 'type' => 'select',
924: 'default' => '',
925: 'options' => $yesno,
926: 'css' => 'width: 300px;',
927: ),
928: );
929: return $this->form_fields;
930: }
931:
932: 933: 934: 935: 936:
937: private function _initConfig($config) {
938: foreach ($this->_config_array as $configKey) {
939: if (isset($config[$this->_config_prefix . $configKey])) {
940: $classProperty = '_' . strtolower($configKey);
941: $this->$classProperty = $config[$this->_config_prefix . $configKey];
942: }
943: }
944: }
945:
946: 947: 948: 949: 950: 951:
952: private function _getConfigArray($prefix, $array) {
953: $result = array();
954: foreach ($array as $value) {
955: $result[] = $prefix.$value;
956: }
957: return $result;
958: }
959:
960:
961:
962:
963:
964: 965: 966: 967: 968: 969: 970: 971: 972: 973: 974:
975: public function upgrade_module_0_6() {
976:
977:
978:
979: 980: 981: 982: 983: 984:
985: $key = self::CONST_PREFIX . 'SEND_STATUS';
986:
987:
988:
989: $orderState = new OrderState(null, Configuration::get('PS_LANG_DEFAULT'));
990: $orderState->invoice = 0;
991: $orderState->send_email = 0;
992: $orderState->color = '#7dffa3';
993: $orderState->unremovable = '1';
994: $orderState->logable = '1';
995: $orderState->delivery = '0';
996:
997: $orderState->name = $this->l('Pending, Customer accepted for COD');
998:
999:
1000:
1001: $orderState->save();
1002:
1003:
1004:
1005: $insertId = $orderState->id;
1006:
1007: $db = Db::getInstance();
1008:
1009: $languages = Language::getLanguages(false);
1010: foreach ($languages as $language) {
1011:
1012: if ($language['id_lang'] != Configuration::get('PS_LANG_DEFAULT')) {
1013: $db->insert('order_state_lang', array(
1014: 'id_order_state' => $db->escape($insertId),
1015: 'id_lang' => $db->escape($language['id_lang']),
1016: 'name' => $db->escape($this->l('Pending, Customer accepted for COD')),
1017:
1018: 'template' => '',
1019: ));
1020: }
1021: }
1022:
1023:
1024:
1025: Configuration::updateValue($key, $orderState->id);
1026:
1027:
1028:
1029: return $this->registerHook('actionOrderStatusPostUpdate');
1030: }
1031:
1032: }
1033: