Preorder: Creates preorder stockchange records, and transactions get has_preorder flag

main
Ashelyn Dawn 3 years ago
parent f9d62847ba
commit a01be76515

@ -23,7 +23,10 @@ module.exports = [{
'item_total_price',
'coupon_effective_discount',
'shipping_price',
'tax_price'
'tax_price',
'has_preorder',
'preorder_fulfill_date',
'preorder_ready_to_ship'
],
associations: [
{name: 'cart', mapId: 'cartMap', columnPrefix: 'cart_'},

@ -132,6 +132,9 @@ create or replace view sos.v_order as
+ case when (coupon_free_shipping != true) then transaction_shipping_price else 0 end
+ coalesce(transaction_tax_price, 0)
) as transaction_computed_price,
(case when stockchange_type = 'preorder' then true else false end) as transaction_has_preorder,
stockchange_preorder_estimated_fulfill_date as transaction_preorder_fulfill_date,
stockchange_preorder_ready_to_ship as transaction_preorder_ready_to_ship,
"coupon".*,
"address".*,
v_transaction_paid.transaction_amount_paid_cents,
@ -145,7 +148,8 @@ create or replace view sos.v_order as
left join sos.v_transaction_paid on "transaction".transaction_uuid = v_transaction_paid.transaction_uuid
left join sos.v_payment on "transaction".transaction_uuid = payment_transaction_uuid
left join sos.v_delivery on "order".order_delivery_uuid = delivery_uuid
left join sos.v_cart on cart_uuid = transaction_cart_uuid;
left join sos.v_cart on cart_uuid = transaction_cart_uuid
left join sos.item_stockchange_preorder on stockchange_transaction_uuid = transaction.transaction_uuid;
create or replace view sos.v_config as
select * from sos."config"

@ -986,7 +986,9 @@ declare
_item_uuids uuid[];
_cart_uuid uuid;
_item_uuid uuid;
_item_count integer;
_cart_item_count integer;
_available_item_count integer;
_item_availability_date timestamptz;
_stockchange_uuid uuid;
begin
-- Get cart uuid (and check completed)
@ -1009,31 +1011,65 @@ begin
-- Make stock-change record for each item
foreach _item_uuid in array _item_uuids loop
select cart_item_count into _item_count from sos."cart_item"
-- Get cart and item info
select cart_item_count into _cart_item_count from sos."cart_item"
where cart_item_cart_uuid = _cart_uuid
and cart_item_item_uuid = _item_uuid;
insert into sos."item_stockchange" (
stockchange_type,
stockchange_item_uuid,
stockchange_change,
stockchange_direction
) values (
'purchase',
_item_uuid,
_item_count,
'subtracted'
) returning stockchange_uuid into _stockchange_uuid;
insert into sos."item_stockchange_purchase" (
stockchange_uuid,
stockchange_type,
stockchange_transaction_uuid
) values (
_stockchange_uuid,
'purchase',
_transaction_uuid
);
select
item_number_in_stock, item_preorder_availability_date
into _available_item_count, _item_availability_date
from sos.v_item
where item_uuid = _item_uuid;
-- Pre-order stockchange
if _cart_item_count > _available_item_count and _item_availability_date is not null then
insert into sos."item_stockchange" (
stockchange_type,
stockchange_item_uuid,
stockchange_change,
stockchange_direction
) values (
'preorder',
_item_uuid,
_cart_item_count,
'subtracted'
) returning stockchange_uuid into _stockchange_uuid;
insert into sos."item_stockchange_preorder" (
stockchange_uuid,
stockchange_type,
stockchange_transaction_uuid,
stockchange_preorder_estimated_fulfill_date
) values (
_stockchange_uuid,
'preorder',
_transaction_uuid,
_item_availability_date
);
else -- Non-preorder stockchange
insert into sos."item_stockchange" (
stockchange_type,
stockchange_item_uuid,
stockchange_change,
stockchange_direction
) values (
'purchase',
_item_uuid,
_cart_item_count,
'subtracted'
) returning stockchange_uuid into _stockchange_uuid;
insert into sos."item_stockchange_purchase" (
stockchange_uuid,
stockchange_type,
stockchange_transaction_uuid
) values (
_stockchange_uuid,
'purchase',
_transaction_uuid
);
end if;
end loop;
return query select * from sos.v_item where item_uuid = any(_item_uuids);

Loading…
Cancel
Save