Revision e3b06f85
Von Werner Hahn vor etwa 7 Jahren hinzugefügt
SL/DB/ShopOrder.pm | ||
---|---|---|
16 | 16 |
column_map => { id => 'shop_order_id' }, |
17 | 17 |
type => 'one to many', |
18 | 18 |
}, |
19 |
customer => { |
|
20 |
class => 'SL::DB::Customer', |
|
21 |
column_map => { kivi_customer_id => 'id' }, |
|
22 |
type => 'one to many', |
|
23 |
}, |
|
24 |
shop => { |
|
25 |
class => 'SL::DB::Shop', |
|
26 |
column_map => { shop_id => 'id' }, |
|
27 |
type => 'one to many', |
|
28 |
}, |
|
29 | 19 |
); |
30 | 20 |
|
31 | 21 |
__PACKAGE__->meta->initialize; |
... | ... | |
46 | 36 |
|
47 | 37 |
my @items = map{ |
48 | 38 |
|
49 |
# TODO Flash and exit if part not found |
|
50 | 39 |
my $part = SL::DB::Manager::Part->find_by(partnumber => $_->partnumber); |
51 | 40 |
|
52 | 41 |
unless($part){ |
53 | 42 |
push @error_report, t8('Part with partnumber: #1 not found', $_->partnumber); |
54 | 43 |
}else{ |
55 |
my $shop_part = SL::DB::Manager::ShopPart->get_all( where => [ shop_id => $self->shop_id, part_id => $part->id] )->[0]; |
|
56 |
|
|
57 |
my @cvars = map { ($_->config->name => { value => $_->value_as_text, is_valid => $_->is_valid }) } @{ $part->cvars_by_config } ; |
|
58 |
my $current_order_item = |
|
59 |
SL::DB::OrderItem->new(parts_id => $part->id, |
|
60 |
description => $part->description, |
|
61 |
qty => $_->quantity, |
|
62 |
sellprice => $_->price, |
|
63 |
unit => $part->unit, |
|
64 |
position => $_->position, |
|
65 |
active_price_source => $shop_part->active_price_source, |
|
66 |
); |
|
44 |
my $shop_part = SL::DB::Manager::ShopPart->find_by( shop_id => $self->shop_id, part_id => $part->id ); |
|
45 |
|
|
46 |
my $current_order_item = SL::DB::OrderItem->new( |
|
47 |
parts_id => $part->id, |
|
48 |
description => $part->description, |
|
49 |
qty => $_->quantity, |
|
50 |
sellprice => $_->price, |
|
51 |
unit => $part->unit, |
|
52 |
position => $_->position, |
|
53 |
active_price_source => $shop_part->active_price_source, |
|
54 |
); |
|
67 | 55 |
} |
68 | 56 |
}@{ $self->shop_order_items }; |
69 | 57 |
|
... | ... | |
71 | 59 |
|
72 | 60 |
my $shipto_id; |
73 | 61 |
if ($self->billing_firstname ne $self->delivery_firstname || $self->billing_lastname ne $self->delivery_lastname || $self->billing_city ne $self->delivery_city || $self->billing_street ne $self->delivery_street) { |
74 |
if(my $address = SL::DB::Manager::Shipto->find_by( shiptoname => $self->delivery_firstname . " " . $self->delivery_lastname,
|
|
75 |
shiptostreet => $self->delivery_street,
|
|
76 |
shiptocity => $self->delivery_city,
|
|
62 |
if(my $address = SL::DB::Manager::Shipto->find_by( shiptoname => $self->delivery_firstname . " " . $self->delivery_lastname, |
|
63 |
shiptostreet => $self->delivery_street,
|
|
64 |
shiptocity => $self->delivery_city,
|
|
77 | 65 |
)) { |
78 | 66 |
$shipto_id = $address->{shipto_id}; |
79 | 67 |
} else { |
80 | 68 |
my $deliveryaddress = SL::DB::Shipto->new; |
81 | 69 |
$deliveryaddress->assign_attributes( |
82 |
shiptoname => $self->delivery_firstname . " " . $self->delivery_lastname,
|
|
83 |
shiptodepartment_1 => $self->delivery_company,
|
|
84 |
shiptodepartment_2 => $self->delivery_department,
|
|
85 |
shiptostreet => $self->delivery_street,
|
|
86 |
shiptozipcode => $self->delivery_zipcode,
|
|
87 |
shiptocity => $self->delivery_city,
|
|
88 |
shiptocountry => $self->delivery_country,
|
|
89 |
trans_id => $customer->id,
|
|
90 |
module => "CT",
|
|
70 |
shiptoname => $self->delivery_firstname . " " . $self->delivery_lastname, |
|
71 |
shiptodepartment_1 => $self->delivery_company, |
|
72 |
shiptodepartment_2 => $self->delivery_department, |
|
73 |
shiptostreet => $self->delivery_street, |
|
74 |
shiptozipcode => $self->delivery_zipcode, |
|
75 |
shiptocity => $self->delivery_city, |
|
76 |
shiptocountry => $self->delivery_country, |
|
77 |
trans_id => $customer->id, |
|
78 |
module => "CT", |
|
91 | 79 |
); |
92 | 80 |
$deliveryaddress->save; |
93 | 81 |
$shipto_id = $deliveryaddress->{shipto_id}; |
... | ... | |
95 | 83 |
} |
96 | 84 |
|
97 | 85 |
my $order = SL::DB::Order->new( |
98 |
amount => $self->amount,
|
|
99 |
cusordnumber => $self->shop_ordernumber,
|
|
100 |
customer_id => $customer->id,
|
|
101 |
shipto_id => $shipto_id,
|
|
102 |
orderitems => [ @items ],
|
|
103 |
employee_id => $employee->id,
|
|
104 |
intnotes => ($customer->notes ne "" ? "\n[Kundestammdaten]\n" . $customer->notes : ""),
|
|
105 |
salesman_id => $employee->id,
|
|
106 |
taxincluded => $self->tax_included,
|
|
107 |
payment_id => $customer->payment_id,
|
|
108 |
taxzone_id => $customer->taxzone_id,
|
|
109 |
currency_id => $customer->currency_id,
|
|
110 |
transaction_description => 'Shop Import',
|
|
111 |
transdate => DateTime->today_local
|
|
112 |
);
|
|
86 |
amount => $self->amount, |
|
87 |
cusordnumber => $self->shop_ordernumber, |
|
88 |
customer_id => $customer->id, |
|
89 |
shipto_id => $shipto_id, |
|
90 |
orderitems => [ @items ], |
|
91 |
employee_id => $employee->id, |
|
92 |
intnotes => $customer->notes,
|
|
93 |
salesman_id => $employee->id, |
|
94 |
taxincluded => $self->tax_included, |
|
95 |
payment_id => $customer->payment_id, |
|
96 |
taxzone_id => $customer->taxzone_id, |
|
97 |
currency_id => $customer->currency_id, |
|
98 |
transaction_description => 'Shop Import', |
|
99 |
transdate => DateTime->today_local |
|
100 |
); |
|
113 | 101 |
return $order; |
114 | 102 |
}else{ |
115 | 103 |
my %error_order = (error => 1, |
116 | 104 |
errors => [ @error_report ], |
117 |
); |
|
105 |
);
|
|
118 | 106 |
return \%error_order; |
119 | 107 |
} |
120 | 108 |
}; |
Auch abrufbar als: Unified diff
Shopmodul: syntax in shoporder