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

Language PHP Lines 162
MD5 Hash 79aa7bdd57f7b2ed7ffcdbe30a93b934 Estimated Cost $3,095 (why?)
Repository https://bitbucket.org/seyar/ari100krat.local View Raw File View Project SPDX
  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
157
158
159
160
161
162
<?php defined('SYSPATH') OR die('No direct access allowed.');
/* @version $Id: v 0.1 05.08.2010 - 15:29:49 Exp $
 *
 * Project:     stream-of-time
 * File:        ukrpost.php * 
 *
 * This library is commercial distributed software; you can't
 * redistribute it and/or modify it without owner (or author) approval.
 *
 * @link http://bestartdesign.com
 * @Best IT Solutions (C) 2010
 * 
 * @author Seyar Chapuh <seyarchapuh@gmail.com>, <sc@bestitsolutions.biz>
 */

class Model_Shipmethods_Ukrpost extends Model_ShipMethods
{
    public $method = 'Ukrpost';
    public $sum = 0;
    public $weight = 0;

    public function show()
    {
        die('func show');
    }

    public function getItem($id)
    {
        $parent = parent::getMainItem(array('id'=>$id, 'fs_name' => $this->method) );
        
        $result =
            DB::select()
            ->from('shipmethod_'.strtolower($this->method))
            ->where('id','=',  $parent['settings_id'])
            ->execute()
            ;
        
        if( $result->count() == 0 ) return array();
        else{
            $return = $result->current();            
            
            return array_merge($return, $parent);
        }
    }
    
    public function addItem($lang_id = 1)
    {
        if ($post = $this->validate_save())
        {
            list($id, $total_rows) =
                            DB::insert('shipmethod_'.strtolower($this->method), array('cost','percent') )
			    ->values(
				    array(
					number_format($post['cost'],2,'.',''),
					number_format($post['percent'],2,'.',''),
					)
				)
//			    ->where('id', '=', $id)
			    ->execute()
                        ;

            list($id, $total_rows) =
                            DB::insert('shop_shipment_methods', array('settings_id','fs_name','name','description','text', 'letter_description','orderid') )
			    ->values(
				    array(
                                        $id,
                                        $post['basic_fs_name'],
					$post['name'],
					$post['description'],
					$post['text'],
					$post['letter_description'],
					$post['orderid'],
					)
				)
//			    ->where('id', '=', $id)
			    ->execute()
                        ;

            return $id;
        }else {
            return false;
        }
    }

    public function save($id, $lang_id = 1)
    {
        if ($post = $this->validate_save())
        {            
                    $parent = parent::getMainItem(array('id'=>$id, 'fs_name' => $this->method) );
                    DB::update('shipmethod_'.strtolower($this->method))
			    ->set(
				    array(
					'cost' => number_format($post['cost'],2,'.',''),
					'percent' => number_format($post['percent'],2,'.',''),
					)
				)
			    ->where('id', '=', $parent['settings_id'])
			    ->execute()
                        ;
                    
                    DB::update('shop_shipment_methods')
			    ->set(
				    array(
					'name' => $post['name'],
					'description' => $post['description'],
					'text' => $post['text'],
					'letter_description' => $post['letter_description'],
					'orderid' => $post['orderid'],
					)
				)
			    ->where('id', '=', $parent['id'])
			    ->execute()
                        ;
                    
	    return $id;
        }else {
            return false;
        }
    }

    public function validate_save()
    {
        $keys = array (
                'cost' ,
                'percent' ,
                'name' ,
                'description' ,
                'text' ,
                'basic_fs_name',
                'letter_description',
                'orderid',
            );
	$params = Arr::extract($_POST, $keys, '');

	$post = Validate::factory($params)

                        ->rule('cost', 'not_empty')
                        ->rule('name', 'not_empty')
                        ->rule('percent', 'not_empty')
                        ->rule('basic_fs_name', 'not_empty')
//                        ->rule('percent', 'digit')
            ;

        if ($post->check())
	{
	    return $params;
	}
	else
        Messages::add($post->errors('validate'));
    }

    public function getCost($method_id = NULL)
    {
        if($method_id)
        {
            $method = $this->getItem($method_id);

            return (float)$method['cost']+$this->weight*(float)$method['percent'];
        }
    }
}
?>
Back to Top