PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 1ms app.codeStats 0ms

/modules/shop/classes/model/shipmethods/ukrpost.php

https://bitbucket.org/seyar/ari100krat.local
PHP | 162 lines | 128 code | 18 blank | 16 comment | 6 complexity | 79aa7bdd57f7b2ed7ffcdbe30a93b934 MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php defined('SYSPATH') OR die('No direct access allowed.');
  2. /* @version $Id: v 0.1 05.08.2010 - 15:29:49 Exp $
  3. *
  4. * Project: stream-of-time
  5. * File: ukrpost.php *
  6. *
  7. * This library is commercial distributed software; you can't
  8. * redistribute it and/or modify it without owner (or author) approval.
  9. *
  10. * @link http://bestartdesign.com
  11. * @Best IT Solutions (C) 2010
  12. *
  13. * @author Seyar Chapuh <seyarchapuh@gmail.com>, <sc@bestitsolutions.biz>
  14. */
  15. class Model_Shipmethods_Ukrpost extends Model_ShipMethods
  16. {
  17. public $method = 'Ukrpost';
  18. public $sum = 0;
  19. public $weight = 0;
  20. public function show()
  21. {
  22. die('func show');
  23. }
  24. public function getItem($id)
  25. {
  26. $parent = parent::getMainItem(array('id'=>$id, 'fs_name' => $this->method) );
  27. $result =
  28. DB::select()
  29. ->from('shipmethod_'.strtolower($this->method))
  30. ->where('id','=', $parent['settings_id'])
  31. ->execute()
  32. ;
  33. if( $result->count() == 0 ) return array();
  34. else{
  35. $return = $result->current();
  36. return array_merge($return, $parent);
  37. }
  38. }
  39. public function addItem($lang_id = 1)
  40. {
  41. if ($post = $this->validate_save())
  42. {
  43. list($id, $total_rows) =
  44. DB::insert('shipmethod_'.strtolower($this->method), array('cost','percent') )
  45. ->values(
  46. array(
  47. number_format($post['cost'],2,'.',''),
  48. number_format($post['percent'],2,'.',''),
  49. )
  50. )
  51. // ->where('id', '=', $id)
  52. ->execute()
  53. ;
  54. list($id, $total_rows) =
  55. DB::insert('shop_shipment_methods', array('settings_id','fs_name','name','description','text', 'letter_description','orderid') )
  56. ->values(
  57. array(
  58. $id,
  59. $post['basic_fs_name'],
  60. $post['name'],
  61. $post['description'],
  62. $post['text'],
  63. $post['letter_description'],
  64. $post['orderid'],
  65. )
  66. )
  67. // ->where('id', '=', $id)
  68. ->execute()
  69. ;
  70. return $id;
  71. }else {
  72. return false;
  73. }
  74. }
  75. public function save($id, $lang_id = 1)
  76. {
  77. if ($post = $this->validate_save())
  78. {
  79. $parent = parent::getMainItem(array('id'=>$id, 'fs_name' => $this->method) );
  80. DB::update('shipmethod_'.strtolower($this->method))
  81. ->set(
  82. array(
  83. 'cost' => number_format($post['cost'],2,'.',''),
  84. 'percent' => number_format($post['percent'],2,'.',''),
  85. )
  86. )
  87. ->where('id', '=', $parent['settings_id'])
  88. ->execute()
  89. ;
  90. DB::update('shop_shipment_methods')
  91. ->set(
  92. array(
  93. 'name' => $post['name'],
  94. 'description' => $post['description'],
  95. 'text' => $post['text'],
  96. 'letter_description' => $post['letter_description'],
  97. 'orderid' => $post['orderid'],
  98. )
  99. )
  100. ->where('id', '=', $parent['id'])
  101. ->execute()
  102. ;
  103. return $id;
  104. }else {
  105. return false;
  106. }
  107. }
  108. public function validate_save()
  109. {
  110. $keys = array (
  111. 'cost' ,
  112. 'percent' ,
  113. 'name' ,
  114. 'description' ,
  115. 'text' ,
  116. 'basic_fs_name',
  117. 'letter_description',
  118. 'orderid',
  119. );
  120. $params = Arr::extract($_POST, $keys, '');
  121. $post = Validate::factory($params)
  122. ->rule('cost', 'not_empty')
  123. ->rule('name', 'not_empty')
  124. ->rule('percent', 'not_empty')
  125. ->rule('basic_fs_name', 'not_empty')
  126. // ->rule('percent', 'digit')
  127. ;
  128. if ($post->check())
  129. {
  130. return $params;
  131. }
  132. else
  133. Messages::add($post->errors('validate'));
  134. }
  135. public function getCost($method_id = NULL)
  136. {
  137. if($method_id)
  138. {
  139. $method = $this->getItem($method_id);
  140. return (float)$method['cost']+$this->weight*(float)$method['percent'];
  141. }
  142. }
  143. }
  144. ?>