767 |
767 |
my $position = 0;
|
768 |
768 |
my $active_price_source = $self->config->price_source;
|
769 |
769 |
#Mapping Positions
|
|
770 |
my %discount_identifier;
|
770 |
771 |
foreach my $pos (@positions) {
|
771 |
772 |
$position++;
|
|
773 |
if ($pos->{type} eq 'promotion') {
|
|
774 |
next unless $pos->{payload}->{discountType} eq 'percentage';
|
|
775 |
foreach my $discount_pos (@{ $pos->{payload}->{composition} }) {
|
|
776 |
$discount_identifier{$discount_pos->{id}} = { discount_percentage => $pos->{payload}->{value},
|
|
777 |
discount_code => $pos->{payload}->{code} };
|
|
778 |
}
|
|
779 |
use Data::Dumper;
|
|
780 |
$main::lxdebug->message(0, 'referenzierte rabatte' . Dumper %discount_identifier);
|
|
781 |
next;
|
|
782 |
}
|
772 |
783 |
my $price = $::form->round_amount($pos->{unitPrice}, 2); # unit
|
773 |
784 |
my %pos_columns = ( description => $pos->{product}->{name},
|
774 |
785 |
partnumber => $pos->{product}->{productNumber},
|
... | ... | |
779 |
790 |
shop_trans_id => $pos->{id}, # pos id or shop_trans_id ? or dont care?
|
780 |
791 |
shop_order_id => $id,
|
781 |
792 |
active_price_source => $active_price_source,
|
|
793 |
identifier => $pos->{identifier},
|
782 |
794 |
);
|
783 |
795 |
my $pos_insert = SL::DB::ShopOrderItem->new(%pos_columns);
|
784 |
796 |
$pos_insert->save;
|
785 |
797 |
}
|
|
798 |
# add discount if percentage
|
|
799 |
while ((my $identifier, my $discount_ref) = each (%discount_identifier)) {
|
|
800 |
# load and update shop order position
|
|
801 |
my $soi = SL::DB::ShopOrderItem->find_by(identifier => $identifier);
|
|
802 |
die "No Shop Order Item for discount found! identfier: " . $identifier unless ref $soi eq 'SL::DB::ShopOrderItem';
|
|
803 |
|
|
804 |
$soi->update_attributes(discount => $discount_ref->{discount_percentage} / 100,
|
|
805 |
discount_code => $discount_ref->{discount_code} );
|
|
806 |
}
|
786 |
807 |
$shop_order->positions($position);
|
787 |
808 |
|
788 |
809 |
if ( $self->config->shipping_costs_parts_id ) {
|
Shopware6: Prozentualen Rabatt aus API auslesen und Konvertieren