| 1 | 2 | ▶ | use utf8; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | |||||||||||
| 3 | package Interchange6::Schema::Result::Order; | ||||||||||
| 4 | |||||||||||
| 5 | =head1 NAME | ||||||||||
| 6 | |||||||||||
| 7 | Interchange6::Schema::Result::Order | ||||||||||
| 8 | |||||||||||
| 9 | =cut | ||||||||||
| 10 | |||||||||||
| 11 | 2 | ▶ | use Interchange6::Schema::Candy -components => [qw(InflateColumn::DateTime)]; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | =head1 ACCESSORS | ||||||||||
| 14 | |||||||||||
| 15 | =head2 orders_id | ||||||||||
| 16 | |||||||||||
| 17 | Primary key. | ||||||||||
| 18 | |||||||||||
| 19 | =cut | ||||||||||
| 20 | |||||||||||
| 21 | 2 | primary_column orders_id => { | |||||||||
| 22 | data_type => "integer", | ||||||||||
| 23 | is_auto_increment => 1, | ||||||||||
| 24 | sequence => "orders_orders_id_seq", | ||||||||||
| 25 | }; | ||||||||||
| 26 | |||||||||||
| 27 | =head2 order_number | ||||||||||
| 28 | |||||||||||
| 29 | Unique representation of the order. | ||||||||||
| 30 | |||||||||||
| 31 | =cut | ||||||||||
| 32 | |||||||||||
| 33 | 2 | unique_column order_number => { | |||||||||
| 34 | data_type => "varchar", | ||||||||||
| 35 | size => 24 | ||||||||||
| 36 | }; | ||||||||||
| 37 | |||||||||||
| 38 | =head2 order_date | ||||||||||
| 39 | |||||||||||
| 40 | Timestamp of when the order was placed. Is nullable. | ||||||||||
| 41 | |||||||||||
| 42 | =cut | ||||||||||
| 43 | |||||||||||
| 44 | 2 | column order_date => { | |||||||||
| 45 | data_type => "timestamp", | ||||||||||
| 46 | is_nullable => 1 | ||||||||||
| 47 | }; | ||||||||||
| 48 | |||||||||||
| 49 | =head2 users_id | ||||||||||
| 50 | |||||||||||
| 51 | Foreign key constraint on L<Interchange6::Schema::Result::User/users_id> | ||||||||||
| 52 | via L</user> relationship. | ||||||||||
| 53 | |||||||||||
| 54 | =cut | ||||||||||
| 55 | |||||||||||
| 56 | 2 | column users_id => { | |||||||||
| 57 | data_type => "integer", | ||||||||||
| 58 | is_foreign_key => 1, | ||||||||||
| 59 | }; | ||||||||||
| 60 | |||||||||||
| 61 | =head2 email | ||||||||||
| 62 | |||||||||||
| 63 | Email address used for the order. Default is empty string | ||||||||||
| 64 | |||||||||||
| 65 | =cut | ||||||||||
| 66 | |||||||||||
| 67 | 2 | column email => { | |||||||||
| 68 | data_type => "varchar", | ||||||||||
| 69 | default_value => "", | ||||||||||
| 70 | size => 255 | ||||||||||
| 71 | }; | ||||||||||
| 72 | |||||||||||
| 73 | =head2 shipping_addresses_id | ||||||||||
| 74 | |||||||||||
| 75 | Foreign key constraint on L<Interchange6::Schema::Result::Address/addresses_id> | ||||||||||
| 76 | via L</shipping_address> relationship. | ||||||||||
| 77 | |||||||||||
| 78 | =cut | ||||||||||
| 79 | |||||||||||
| 80 | 2 | column shipping_addresses_id => { | |||||||||
| 81 | data_type => "integer", | ||||||||||
| 82 | is_foreign_key => 1 | ||||||||||
| 83 | }; | ||||||||||
| 84 | |||||||||||
| 85 | =head2 billing_addresses_id | ||||||||||
| 86 | |||||||||||
| 87 | Foreign key constraint on L<Interchange6::Schema::Result::Address/addresses_id> | ||||||||||
| 88 | via L</billing_address> relationship. | ||||||||||
| 89 | |||||||||||
| 90 | =cut | ||||||||||
| 91 | |||||||||||
| 92 | 2 | column billing_addresses_id => { | |||||||||
| 93 | data_type => "integer", | ||||||||||
| 94 | is_foreign_key => 1 | ||||||||||
| 95 | }; | ||||||||||
| 96 | |||||||||||
| 97 | =head2 weight | ||||||||||
| 98 | |||||||||||
| 99 | Total numeric weight of the order. Default is 0.0. | ||||||||||
| 100 | |||||||||||
| 101 | =cut | ||||||||||
| 102 | |||||||||||
| 103 | 2 | column weight => { | |||||||||
| 104 | data_type => "numeric", | ||||||||||
| 105 | default_value => "0.0", | ||||||||||
| 106 | size => [ 11, 3 ] | ||||||||||
| 107 | }; | ||||||||||
| 108 | |||||||||||
| 109 | =head2 payment_method | ||||||||||
| 110 | |||||||||||
| 111 | This is the type of payment used for the order. | ||||||||||
| 112 | |||||||||||
| 113 | =cut | ||||||||||
| 114 | |||||||||||
| 115 | 2 | column payment_method => { | |||||||||
| 116 | data_type => "varchar", | ||||||||||
| 117 | default_value => "", | ||||||||||
| 118 | size => 255 | ||||||||||
| 119 | }; | ||||||||||
| 120 | |||||||||||
| 121 | =head2 payment_number | ||||||||||
| 122 | |||||||||||
| 123 | A validation record for the payment. | ||||||||||
| 124 | |||||||||||
| 125 | =cut | ||||||||||
| 126 | |||||||||||
| 127 | 2 | column payment_number => { | |||||||||
| 128 | data_type => "varchar", | ||||||||||
| 129 | default_value => "", | ||||||||||
| 130 | size => 255 | ||||||||||
| 131 | }; | ||||||||||
| 132 | |||||||||||
| 133 | =head2 payment_status | ||||||||||
| 134 | |||||||||||
| 135 | The status of the payment for the current order. | ||||||||||
| 136 | |||||||||||
| 137 | =cut | ||||||||||
| 138 | |||||||||||
| 139 | 2 | column payment_status => { | |||||||||
| 140 | data_type => "varchar", | ||||||||||
| 141 | default_value => "", | ||||||||||
| 142 | size => 255 | ||||||||||
| 143 | }; | ||||||||||
| 144 | |||||||||||
| 145 | =head2 shipping_method | ||||||||||
| 146 | |||||||||||
| 147 | What shipping method was used for the order. | ||||||||||
| 148 | |||||||||||
| 149 | =cut | ||||||||||
| 150 | |||||||||||
| 151 | 2 | column shipping_method => { | |||||||||
| 152 | data_type => "varchar", | ||||||||||
| 153 | default_value => "", | ||||||||||
| 154 | size => 255 | ||||||||||
| 155 | }; | ||||||||||
| 156 | |||||||||||
| 157 | =head2 subtotal | ||||||||||
| 158 | |||||||||||
| 159 | The sum of all items in the cart before tax and shipping costs. | ||||||||||
| 160 | |||||||||||
| 161 | =cut | ||||||||||
| 162 | |||||||||||
| 163 | 2 | column subtotal => { | |||||||||
| 164 | data_type => "numeric", | ||||||||||
| 165 | default_value => "0.0", | ||||||||||
| 166 | size => [ 11, 2 ], | ||||||||||
| 167 | }; | ||||||||||
| 168 | |||||||||||
| 169 | =head2 shipping | ||||||||||
| 170 | |||||||||||
| 171 | The numeric cost associated with shipping the order. Default is 0.0. | ||||||||||
| 172 | |||||||||||
| 173 | =cut | ||||||||||
| 174 | |||||||||||
| 175 | 2 | column shipping => { | |||||||||
| 176 | data_type => "numeric", | ||||||||||
| 177 | default_value => "0.0", | ||||||||||
| 178 | size => [ 11, 2 ], | ||||||||||
| 179 | }; | ||||||||||
| 180 | |||||||||||
| 181 | =head2 handling | ||||||||||
| 182 | |||||||||||
| 183 | The numeric cost associated with handling the order. Default is 0.0. | ||||||||||
| 184 | |||||||||||
| 185 | =cut | ||||||||||
| 186 | |||||||||||
| 187 | 2 | column handling => { | |||||||||
| 188 | data_type => "numeric", | ||||||||||
| 189 | default_value => "0.0", | ||||||||||
| 190 | size => [ 11, 2 ], | ||||||||||
| 191 | }; | ||||||||||
| 192 | |||||||||||
| 193 | =head2 salestax | ||||||||||
| 194 | |||||||||||
| 195 | The total tax applied to the order. Default is 0.0. | ||||||||||
| 196 | |||||||||||
| 197 | =cut | ||||||||||
| 198 | |||||||||||
| 199 | 2 | column salestax => { | |||||||||
| 200 | data_type => "numeric", | ||||||||||
| 201 | default_value => "0.0", | ||||||||||
| 202 | size => [ 11, 2 ], | ||||||||||
| 203 | }; | ||||||||||
| 204 | |||||||||||
| 205 | =head2 total_cost | ||||||||||
| 206 | |||||||||||
| 207 | The total cost of all items shipping handling and tax for the order. Default is 0.0. | ||||||||||
| 208 | |||||||||||
| 209 | =cut | ||||||||||
| 210 | |||||||||||
| 211 | 2 | column total_cost => { | |||||||||
| 212 | data_type => "numeric", | ||||||||||
| 213 | default_value => "0.0", | ||||||||||
| 214 | size => [ 11, 2 ], | ||||||||||
| 215 | }; | ||||||||||
| 216 | |||||||||||
| 217 | =head1 RELATIONS | ||||||||||
| 218 | |||||||||||
| 219 | =head2 shipping_address | ||||||||||
| 220 | |||||||||||
| 221 | Type: belongs_to | ||||||||||
| 222 | |||||||||||
| 223 | Related object: L<Interchange6::Schema::Result::Address> | ||||||||||
| 224 | |||||||||||
| 225 | =cut | ||||||||||
| 226 | |||||||||||
| 227 | 2 | belongs_to | |||||||||
| 228 | shipping_address => "Interchange6::Schema::Result::Address", | ||||||||||
| 229 | { addresses_id => "shipping_addresses_id" }; | ||||||||||
| 230 | |||||||||||
| 231 | =head2 billing_address | ||||||||||
| 232 | |||||||||||
| 233 | Type: belongs_to | ||||||||||
| 234 | |||||||||||
| 235 | Related object: L<Interchange6::Schema::Result::Address> | ||||||||||
| 236 | |||||||||||
| 237 | =cut | ||||||||||
| 238 | |||||||||||
| 239 | 2 | belongs_to | |||||||||
| 240 | billing_address => "Interchange6::Schema::Result::Address", | ||||||||||
| 241 | { addresses_id => "billing_addresses_id" }; | ||||||||||
| 242 | |||||||||||
| 243 | =head2 orderlines | ||||||||||
| 244 | |||||||||||
| 245 | Type: has_many | ||||||||||
| 246 | |||||||||||
| 247 | Related object: L<Interchange6::Schema::Result::Orderline> | ||||||||||
| 248 | |||||||||||
| 249 | =cut | ||||||||||
| 250 | |||||||||||
| 251 | 2 | has_many | |||||||||
| 252 | orderlines => "Interchange6::Schema::Result::Orderline", | ||||||||||
| 253 | "orders_id", | ||||||||||
| 254 | { cascade_copy => 0, cascade_delete => 0 }; | ||||||||||
| 255 | |||||||||||
| 256 | =head2 payment_orders | ||||||||||
| 257 | |||||||||||
| 258 | Type: has_many | ||||||||||
| 259 | |||||||||||
| 260 | Related object: L<Interchange6::Schema::Result::PaymentOrder> | ||||||||||
| 261 | |||||||||||
| 262 | =cut | ||||||||||
| 263 | |||||||||||
| 264 | 2 | has_many | |||||||||
| 265 | payment_orders => "Interchange6::Schema::Result::PaymentOrder", | ||||||||||
| 266 | "orders_id", | ||||||||||
| 267 | { cascade_copy => 0, cascade_delete => 0 }; | ||||||||||
| 268 | |||||||||||
| 269 | =head2 user | ||||||||||
| 270 | |||||||||||
| 271 | Type: belongs_to | ||||||||||
| 272 | |||||||||||
| 273 | Related object: L<Interchange6::Schema::Result::User> | ||||||||||
| 274 | |||||||||||
| 275 | =cut | ||||||||||
| 276 | |||||||||||
| 277 | 2 | belongs_to | |||||||||
| 278 | user => "Interchange6::Schema::Result::User", | ||||||||||
| 279 | "users_id", | ||||||||||
| 280 | { is_deferrable => 1, on_delete => "CASCADE", on_update => "CASCADE" }; | ||||||||||
| 281 | |||||||||||
| 282 | =head2 order_comments | ||||||||||
| 283 | |||||||||||
| 284 | Type: has_many | ||||||||||
| 285 | |||||||||||
| 286 | Related object: L<Interchange6::Schema::Result::OrderComment> | ||||||||||
| 287 | |||||||||||
| 288 | =cut | ||||||||||
| 289 | |||||||||||
| 290 | 2 | has_many | |||||||||
| 291 | order_comments => 'Interchange6::Schema::Result::OrderComment', | ||||||||||
| 292 | 'orders_id'; | ||||||||||
| 293 | |||||||||||
| 294 | =head2 _comments | ||||||||||
| 295 | |||||||||||
| 296 | Type: many_to_many | ||||||||||
| 297 | |||||||||||
| 298 | This is considered a private method. Please see public L</comments> and L</add_to_comments> methods. | ||||||||||
| 299 | |||||||||||
| 300 | =cut | ||||||||||
| 301 | |||||||||||
| 302 | 2 | many_to_many _comments => "order_comments", "message"; | |||||||||
| 303 | |||||||||||
| 304 | =head2 statuses | ||||||||||
| 305 | |||||||||||
| 306 | Type: has_many | ||||||||||
| 307 | |||||||||||
| 308 | Related object: L<Interchange6::Schema::Result::OrderStatus> | ||||||||||
| 309 | |||||||||||
| 310 | =cut | ||||||||||
| 311 | |||||||||||
| 312 | 2 | has_many | |||||||||
| 313 | statuses => 'Interchange6::Schema::Result::OrderStatus', | ||||||||||
| 314 | 'orders_id'; | ||||||||||
| 315 | |||||||||||
| 316 | |||||||||||
| 317 | =head1 METHODS | ||||||||||
| 318 | |||||||||||
| 319 | =head2 comments | ||||||||||
| 320 | |||||||||||
| 321 | =over 4 | ||||||||||
| 322 | |||||||||||
| 323 | =item Arguments: none | ||||||||||
| 324 | |||||||||||
| 325 | =item Return Value: L<Interchange6::Schema::Result::Message> resultset. | ||||||||||
| 326 | |||||||||||
| 327 | =back | ||||||||||
| 328 | |||||||||||
| 329 | =cut | ||||||||||
| 330 | |||||||||||
| 331 | sub comments { | ||||||||||
| 332 | 3 | ▶ | return shift->_comments(@_); | ||||||||
|
Subroutine
comments: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 333 | } | ||||||||||
| 334 | |||||||||||
| 335 | =head2 add_to_comments | ||||||||||
| 336 | |||||||||||
| 337 | =over 4 | ||||||||||
| 338 | |||||||||||
| 339 | =item Arguments: \%col_data | ||||||||||
| 340 | |||||||||||
| 341 | =item Return Value: L<Interchange6::Schema::Result::Message> | ||||||||||
| 342 | |||||||||||
| 343 | =back | ||||||||||
| 344 | |||||||||||
| 345 | See L<DBIx::Class::Relationship::Base/add_to_$rel> many_to_many for further details. | ||||||||||
| 346 | |||||||||||
| 347 | =cut | ||||||||||
| 348 | |||||||||||
| 349 | # much of this was cargo-culted from DBIx::Class::Relationship::ManyToMany | ||||||||||
| 350 | |||||||||||
| 351 | sub add_to_comments { | ||||||||||
| 352 | 4 | ▶ | my $self = shift; | ||||||||
|
Subroutine
add_to_comments: called CC=5 SCAR=19.5
Pod
documented
| |||||||||||
| 353 | 4 | ▶ | @_ > 0 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 354 | or $self->throw_exception("add_to_comments needs an object or hashref"); | ||||||||||
| 355 | 4 | my $rset_message = $self->result_source->schema->resultset("Message"); | |||||||||
| 356 | 4 | my $obj; | |||||||||
| 357 | 4 | ▶ | if ( ref $_[0] ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 358 | 4 | ▶ | if ( ref $_[0] eq 'HASH' ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 359 | 4 | $_[0]->{type} = "order_comment"; | |||||||||
| 360 | 4 | $obj = $rset_message->create( $_[0] ); | |||||||||
| 361 | } | ||||||||||
| 362 | else { | ||||||||||
| 363 | 0 | $obj = $_[0]; | |||||||||
| 364 | 0 | ▶ | unless ( my $type = $obj->message_type->name eq "order_comment" ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 365 | 0 | $self->throw_exception( | |||||||||
| 366 | "cannot add message type $type to comments"); | ||||||||||
| 367 | } | ||||||||||
| 368 | } | ||||||||||
| 369 | } | ||||||||||
| 370 | else { | ||||||||||
| 371 | 0 | push @_, type => "order_comment"; | |||||||||
| 372 | 0 | $obj = $rset_message->create( {@_} ); | |||||||||
| 373 | } | ||||||||||
| 374 | 3 | $self->create_related( 'order_comments', { messages_id => $obj->id } ); | |||||||||
| 375 | 3 | return $obj; | |||||||||
| 376 | } | ||||||||||
| 377 | |||||||||||
| 378 | =head2 set_comments | ||||||||||
| 379 | |||||||||||
| 380 | =over 4 | ||||||||||
| 381 | |||||||||||
| 382 | =item Arguments: (\@hashrefs_of_col_data | \@result_objs) | ||||||||||
| 383 | |||||||||||
| 384 | =item Return Value: not defined | ||||||||||
| 385 | |||||||||||
| 386 | =back | ||||||||||
| 387 | |||||||||||
| 388 | Similar to L<DBIx::Class::Relationship::Base/set_$rel> except that this method D | ||||||||||
| 389 | OES delete objects in the table on the right side of the relation. | ||||||||||
| 390 | |||||||||||
| 391 | =cut | ||||||||||
| 392 | |||||||||||
| 393 | sub set_comments { | ||||||||||
| 394 | 2 | ▶ | my $self = shift; | ||||||||
|
Subroutine
set_comments: called CC=5 SCAR=17.8
Pod
documented
| |||||||||||
| 395 | 2 | ▶ | @_ > 0 | ||||||||
|
Branch: 1 branch
| |||||||||||
| 396 | or $self->throw_exception( | ||||||||||
| 397 | "set_comments needs a list of objects or hashrefs"); | ||||||||||
| 398 | 2 | ▶ | my @to_set = ( ref( $_[0] ) eq 'ARRAY' ? @{ $_[0] } : @_ ); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 399 | 2 | $self->order_comments->delete_all; | |||||||||
| 400 | 2 | ▶ | $self->add_to_comments( $_, ref( $_[1] ) ? $_[1] : {} ) for (@to_set); | ||||||||
|
Branch: 1 branch
| |||||||||||
| 401 | } | ||||||||||
| 402 | |||||||||||
| 403 | =head2 delete | ||||||||||
| 404 | |||||||||||
| 405 | Overload delete to force removal of any order comments. | ||||||||||
| 406 | |||||||||||
| 407 | =cut | ||||||||||
| 408 | |||||||||||
| 409 | # FIXME: (SysPete) There ought to be a way to force this with cascade delete. | ||||||||||
| 410 | |||||||||||
| 411 | sub delete { | ||||||||||
| 412 | 2 | ▶ | my ( $self, @args ) = @_; | ||||||||
|
Subroutine
delete: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 413 | 2 | my $guard = $self->result_source->schema->txn_scope_guard; | |||||||||
| 414 | 2 | $self->order_comments->delete_all; | |||||||||
| 415 | 2 | $self->next::method(@args); | |||||||||
| 416 | 2 | $guard->commit; | |||||||||
| 417 | } | ||||||||||
| 418 | |||||||||||
| 419 | =head2 status | ||||||||||
| 420 | |||||||||||
| 421 | Option argument C<$status> will cause creation of a new related entry in | ||||||||||
| 422 | L<Interchange6::Schema::Result::Status>. | ||||||||||
| 423 | |||||||||||
| 424 | Returns the most recent L<Interchange6::Schema::Result::Status/status>. | ||||||||||
| 425 | |||||||||||
| 426 | If initial result set was created using | ||||||||||
| 427 | L<Interchange6::Schema::ResultSet::Order/with_status> then the status added | ||||||||||
| 428 | by that method will be returned so that a new query is not required. | ||||||||||
| 429 | |||||||||||
| 430 | =cut | ||||||||||
| 431 | |||||||||||
| 432 | sub status { | ||||||||||
| 433 | 3 | ▶ | my $self = shift; | ||||||||
|
Subroutine
status: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 434 | 3 | ▶ | if ( @_ ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 435 | 1 | return $self->statuses->create( { status => shift } )->status; | |||||||||
| 436 | } | ||||||||||
| 437 | 2 | ▶ | if ( $self->has_column_loaded('status')) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 438 | 1 | return $self->get_column('status'); | |||||||||
| 439 | } | ||||||||||
| 440 | else { | ||||||||||
| 441 | 1 | return $self->statuses->rows(1)->order_by('!created,!order_status_id') | |||||||||
| 442 | ->single->status; | ||||||||||
| 443 | } | ||||||||||
| 444 | } | ||||||||||
| 445 | |||||||||||
| 446 | 2 | 1; | |||||||||