PageRenderTime 37ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/modules/shop/classes/controller/shipmethods.php

https://bitbucket.org/seyar/ari100krat.local
PHP | 135 lines | 109 code | 24 blank | 2 comment | 10 complexity | 434a27d670b73c5d8d5681a3ce33e1ed MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1
  1. <?php
  2. defined( 'SYSPATH' ) OR die( 'No direct access allowed.' );
  3. class Controller_ShipMethods extends Controller_Shop
  4. {
  5. public $template = 'shipmethods_list';
  6. public $module_title = 'Shipment Methods';
  7. public $module_desc_short = 'Shop Descr Short';
  8. public $module_desc_full = 'Shop Descr Full';
  9. public $shipMethods = array( );
  10. public $main_shipments = array( );
  11. public function before()
  12. {
  13. parent::before();
  14. $this->model = new Model_ShipMethods;
  15. //$this->request->controller .= ':' . MODULE_SUBCONTROLLER;
  16. list($this->shipMethods) = $this->model->show();
  17. $this->main_shipments = Kohana::config( 'shop' )->main_shipments;
  18. }
  19. public function action_index()
  20. {
  21. $rows = $current_category = array();
  22. $page_links = '';
  23. $total_pages = 0;
  24. list($rows, $page_links, $total_pages) = $this->model->show();
  25. $this->template->rows = $rows;
  26. $this->template->pages_list = $page_links;
  27. $this->template->total_pages = $total_pages;
  28. }
  29. public function action_delete()
  30. {
  31. if( $this->request->param( 'id' ) )
  32. $this->model->delete( $this->request->param( 'id' ) );
  33. elseif( count( $_POST['chk'] ) )
  34. $this->model->delete_list( $_POST['chk'] );
  35. $this->redirect_to_controller( $this->request->controller );
  36. }
  37. public function action_status()
  38. {
  39. if( $this->request->param( 'id' ) )
  40. $this->model->status( $this->request->param( 'id' ) );
  41. elseif( count( $_POST['chk'] ) )
  42. $this->model->status_list( $_POST['chk'] );
  43. $this->redirect_to_controller( $this->request->controller );
  44. }
  45. public function action_add()
  46. {
  47. $main_shipments = Model_ShipMethods::getAllAvailableShipment( $this->main_shipments );
  48. $this->template = View::factory('shipmethods_add');
  49. $this->template->available_shipment = $main_shipments;
  50. }
  51. public function action_edit()
  52. {
  53. $fs_name = $this->shipMethods[$this->request->param( 'id' )]['fs_name'];
  54. $this->template = View::factory('shipmethods_edit_' . strtolower( $fs_name ) );
  55. $obj = $this->model->setMethod( $fs_name )->getItem( $this->request->param( 'id' ) );
  56. $this->template->obj = $obj;
  57. }
  58. public function action_save()
  59. {
  60. $fs_name = $_POST['basic_fs_name'];
  61. if( $this->request->param( 'id' ) )
  62. $res = $this->model->setMethod( $fs_name )->save( $this->request->param( 'id' ), $this->lang );
  63. else
  64. $res = $this->model->setMethod( $fs_name )->addItem( $this->lang );
  65. if(!Messages::has() && $res )
  66. {
  67. $this->redirect_to_controller( $this->request->controller );
  68. }else
  69. {
  70. $this->action_edit();
  71. }
  72. }
  73. public function action_update()
  74. {
  75. $fs_name = $_POST['basic_fs_name'];
  76. if( $this->request->param( 'id' ) )
  77. $res = $this->model->setMethod( $fs_name )->save( $this->request->param( 'id' ), $this->lang );
  78. else
  79. $res = $this->model->setMethod( $fs_name )->addItem( $this->request->param( 'id' ), $this->lang );
  80. if( $res )
  81. {
  82. $this->redirect_to_controller( $this->request->controller . '/' . $res . '/edit' );
  83. }else
  84. {
  85. $this->action_edit();
  86. }
  87. }
  88. static public function getCost( $method, $weight = 0, $sum = 0 )
  89. {
  90. if( $method == 0 ) return 0;
  91. $method = Model_ShipMethods::getMainItem( array( 'id' => $method ) );
  92. $oMethod = Model_ShipMethods::instance()->setMethod( $method['fs_name'] );
  93. $oMethod->weight = $weight;
  94. $oMethod->sum = $sum;
  95. return $oMethod->getCost( $method['id'] );
  96. }
  97. public function action_next()
  98. {
  99. $this->template = View::factory('shipmethods_edit_' . strtolower( $_POST['fs_name'] ) );
  100. $obj['basic_fs_name'] = $_POST['fs_name'];
  101. // $obj = $this->model->setMethod($_POST['fs_name'])->getItem();
  102. $this->template->obj = $obj;
  103. }
  104. public function action_updateOrderId()
  105. {
  106. if( $this->model->updateOrderId( $_GET['ids'] ))
  107. die('1');
  108. else
  109. die('error');
  110. }
  111. }