... {toc} h1. Discounts * discounts will be provided for baskets only not for orders h2. New Shop Discount Scales h3. Resources h4. Retrieve Shop Discount Scales List || Url | .../v1/shops/\{shopId\}/discountScales || || Sample | [http://api.spreadshirt.net/api/v1/shops/40000/discountScales|http://api.spreadshirt.net/api/v1/shops/40000/discountScales] || || Type | LIST || || Method | GET || || Special Status Codes | || *Response Representation:* \\ \\ {noformat} <discountScales ...> ... </discountScales> {noformat} h4. Retrieve Shop Discount Scale Entity || Url | .../v1/shops/\{shopId\}/discountScales/\{discountScaleId\} || || Sample | [http://api.spreadshirt.net/api/v1/shops/40000/discountScales/1|http://api.spreadshirt.net/api/v1/shops/40000/discountScales/1] || || Type | ENTITY || || Method | GET || || Special Status Codes | || *Response Representation:* {noformat} <discountScale ...> ... </discountScale> {noformat} h3. Representations h4. DiscountScale * discount value ranges should work for quantities and prices ** quantity example 0..4, 5..11, 12..24 ... ** _possible would also be price for currency € example 0..10, 11..20, 21..30 ...._ * discount credits should work as percentage and fixed price ** percentage example 0, 10, 15, 20, 25 ** _possible would also be price example 10, 20, 30, 40, 50 ...._ {code} <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <discountScales xlink:href="http://api.spreadshirt.net/api/v1/shops/205909/discountScales"> <discountScale id="1" xlink:href="http://api.spreadshirt.net/api/v1/shops/205909/discountScales/1"> <!-- sprd:price currency --> <discounts> <discount id="10"> <valueRange> <from>0</from> <to>4</to> <unit type="sprd:quantity"/> </valueRange> <credit> <value>0</value> <unit type="sprd:percentage"/> </credit> <discount> <discount id="11"> <valueRange> <from>5</from> <to>11</to> <unit type="sprd:quantity"/> </valueRange> <credit> <value>10</value> <unit type="sprd:percentage"/> </credit> <discount> <discount id="12"> <valueRange> <from>12</from> <to>24</to> <unit type="sprd:quantity"/> </valueRange> <credit> <value>15</value> <unit type="sprd:percentage"/> </credit> <discount> <discount id="13"> <valueRange> <from>25</from> <to>49</to> <unit type="sprd:quantity"/> </valueRange> <credit> <value>20</value> <unit type="sprd:percentage"/> </credit> <discount> <discount id="14"> <valueRange> <from>50</from> <to>99</to> <unit type="sprd:quantity"/> </valueRange> <credit> <value>25</value> <unit type="sprd:percentage"/> </credit> <discount> <discount id="15"> <valueRange> <from>100</from> <unit type="sprd:quantity"/> </valueRange> <credit> <value>30</value> <unit type="sprd:percentage"/> </credit> <discount> </discounts> </discountScale> </discountScales> {code} h2. ProductType payload changes h3. discountSupported flag on ProductType payload {code} <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <productType ...> ... <shippingFactor>1.0</shippingFactor> <!-- new --> <discountSupported>true</discountSupported> <!-- new --> ... </productType> {code} h2. Shop payload changes h3. discountSupported flag on Shop payload {code} <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <shop ...> ... <!-- new --> <discountSupported>true</discountSupported> <!-- new --> ... </shop> {code} h2. Basket changes h3. Discount info on basket and basket items * add discounts block to basket item - discount for single basket item * add priceItem block to basket item - price of single basket item without discounts, applied coupons * modify basket item price - price of single basket item with discounts and coupons applied * add discounts block to basket - cumulated discounts from basket items * add priceItems block to basket - price of all basket items (quantity * priceItem) without discounts, applied coupons * add priceTotal block to basket \- price of all basket items (quantity * priceItem) with discounts, coupons applied {code} <?xml version="1.0" encoding="UTF-8" standalone="yes"?> <basket id="0cd283f7-5b24-407a-9a9c-a081455e1030" xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://api.spreadshirt.net" xlink:href="http://api.spreadshirt.net/api/v1/baskets/0cd283f7-5b24-407a-9a9c-a081455e1030"> <token>xy</token> <user id="42" xlink:href="http://api.spreadshirt.net/v1/users/42"/> <shop id="42" xlink:href="http://api.spreadshirt.net/v1/shops/42"/> <basketItems> <basketItem xmlns:xlink="http://www.w3.org/1999/xlink" xmlns="http://api.spreadshirt.net" xlink:href="http://api.spreadshirt.net/api/v1/baskets/0cd283f7-5b24-407a-9a9c-a081455e1030/items/a561dcbb-9065-4e45-ad20-aba2bd8a6afa" id="a561dcbb-9065-4e45-ad20-aba2bd8a6afa"> <!-- optional for mixed mode --> <shop id="40000" xlink:href="http://api.spreadshirt.net/v1/shops/42"> <description>Basket Item description</description> <quantity>2</quantity> <element id="456" type="sprd:article" xlink:href="http://api.spreadshirt.net/v1/shops/42/articles/456"> <properties> <property key="appearance">15</property> <property key="size">12</property> </properties> </element> <links> <link type="edit" xlink:href="http://www.yourdomain.de/article/123/edit"/> <link type="continueShopping" xlink:href="http://www.yourdomain.de"/> </links> <!-- for demo only --> <coupons> ... </coupons> <!-- for demo only --> <!-- new --> <discounts> <discount> <discountScale id="1" xlink:href="http://api.spreadshirt.net/api/v1/shops/205909/discountScales/1"/> <currentDiscount id="10"/> <nextDiscount id="11"/> <price> <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/> <vatIncluded>3.0</vatIncluded> <vatExcluded>2.43</vatExcluded> <vat>19.0</vat> </price> </discount> </discounts> <priceItem> <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/> <vatIncluded>10.0</vatIncluded> <vatExcluded>8.1</vatExcluded> <vat>19.00</vat> <priceItem> <price> <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/> <vatIncluded>7.0</vatIncluded> <vatExcluded>5.67</vatExcluded> <vat>19.0</vat> </price> <!-- new --> </basketItem> ... </basketItems> <!-- for demo only --> <coupons> <coupon> ... <price> <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/> <vatIncluded>-5.0</vatIncluded> <vatExcluded>-0.95</vatExcluded> <vat>19.00</vat> <price> </coupon> </coupons> <!-- for demo only --> <shipping> ... <price> <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/> <vatIncluded>5.0</vatIncluded> <vatExcluded>0.95</vatExcluded> <vat>19.00</vat> <price> </shipping> <!-- new --> <discounts> <discount> <discountScale id="1" xlink:href="http://api.spreadshirt.net/api/v1/shops/205909/discountScales/1"/> <currentDiscount id="10"/> <nextDiscount id="11"/> <price> <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/> <vatIncluded>6.0</vatIncluded> <vatExcluded>4.86</vatExcluded> <vat>19.0</vat> </price> </discount> </discounts> <priceItems> <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/> <vatIncluded>20.0</vatIncluded> <vatExcluded>16.2</vatExcluded> <vat>19.00</vat> <priceItems> <priceTotal> <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/> <vatIncluded>14.0</vatIncluded> <vatExcluded>11.34</vatExcluded> <vat>19.0</vat> </priceTotal> <!-- new --> </basket> {code} h3. Discount calculation * only basket item where shop and product type of article/product support discounts are considered * quantities of considered basket items are summed up per used discount scale (for mixed baskets we could have items from different shops with different discount scales - in this case quantities are summed up per used discount scale and not in total) * with the summed up quantities we check the corresponding discount scale for a matching discount - if we find a discount, we store it * we check the basket items again and check whether a discount for the item is granted - in case a discount is granted we calculated the percentage discount on the item * to find out the granted discount for a specific discount scale, we sum up the item discounts {code} possibleDiscounts = map<String,Integer>(); for (basketitem : basket.basketitems) { if (basketitem.productType.supportsDiscounts && basketitem.shop.supportsDiscounts) { // collect quantity per discount scale if (!possibleDiscounts.containsKey(basketitem.shop.discountScale)) { possibleDiscounts.put(basketitem.shop.discountScale, 0); } possibleDiscounts.put(basketitem.shop.discountScale, possibleDiscounts.get(basketitem.shop.discountScale) + basketitem.quantity); } } foundDiscounts = list<String, Discount>(); for (possibleDiscount : possibleDiscounts) { discountScale = getDiscountScale(possibleDiscount.key); quantity = possibleDiscount.value; if (discountScale.discounts[0].valueRange.unit == "sprd:quantity") { for (discount : discountScale.discounts) { if (quantity >= discount.from && (discount.to == null || quantity <= discount.to)) { foundDiscounts.put(possibleDiscount.key, discount); break; } } } } grantedDiscounts = map<String, double>; for (basketitem : basket.basketitems) { if (basketitem.productType.supportsDiscounts && basketitem.shop.supportsDiscounts) { if (foundDiscounts.containsKey(basketitem.shop.discountScale)) { discount = foundDiscounts.get(basketitem.shop.discountScale); if (discount.credit.unit == "sprd:percentage") { if (!grantedDiscounts.containsKey(basketitem.shop.discountScale)) { grantedDiscounts.put(basketitem.shop.discountScale, 0); } grantedDiscounts.put(basketitem.shop.discountScale, grantedDiscounts.get(basketitem.shop.discountScale) + basketitem.price * discount.credit.value/100 * basketitem.quantity); } } } } totalDiscount = 0; for (grantedDiscount : grantedDiscounts) { totalDiscount += grantedDiscount.value; } {code} h1. Basket Modifications h2. Allow to create basket with basket items on POST on /api/v1/baskets h2. Add appearanceLink, appearanceLabel and sizeLabel to basket item {code} <basket ...> <basketItem ...> <shop id="205909" xlink:href="http://api.spreadshirt.net/v1/shops/205909"> <description>Basket Item description</description> <quantity>2</quantity> <element id="123" type="sprd:product" xlink:href="http://api.spreadshirt.net/v1/shops/205909/products/123"> <properties> <property key="appearance">15</property> <property key="size">12</property> <!-- new --> <property key="appearance>Label">Red</property> <property key="sizeLabel">M</property> <property key="appearanceLink">http://image.spreadshirt.net/image-server/v1/appearances/15</property> <!-- new --> </properties> </element> <links> <link type="edit" xlink:href="http://www.yourdomain.de/product/123/edit"/> <link type="continueShopping" xlink:href="http://www.yourdomain.de"/> </links> <price> <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/> <vatIncluded>10.0</vatIncluded> <vatExcluded>9.8</vatExcluded> <vat>0.2</vat> </price> ... </basketItem> ... </basket>
|