Basket Resources

compared with
Current by Rolf Richter
on Dec 11, 2012 11:14.

Key
This line was removed.
This word was removed. This word was added.
This line was added.

Changes (21)

View Page History
{code}

and shop can be added
or full basket payload can be given
{code}
<basket>
<token>xy</token> ...
<shop id="42"/>
</basket>
{code}





*Response Representation:*






h2. Update Basket






h2. Delete Basket






*Response Representation:*






h2. Update Basket Item






h2. Delete Basket Item

| basket/user \\ | Reference to the user (customer) that owns that basket. Null means the basket belongs to no specific customer. \\ |
| basket/basketItems \\ | List of basket items that are actually in the basket. See [Basket Item|#BasketItem] for more details. \\ |
| basket/links | Different links, for example shop checkout link, platform checkout link or default checkout link that is calculated for the current basket. |
| basket/shipping | Shipping data for basket. |
| basket/shipping/shippingType | The selected shippingType. |
| basket/shipping/price | The shipping price. |
| basket/discounts | List of discounts that apply and total discount value (for all basket items \-> basket item discount x basket item quantity). |
| basket/priceItems | Total for all basket items only without shipping cost, discounts, etc. (for all basket items \-> basket price item x basket item quantity). |
| basket/priceTotal | Total for basket with price of all items, discounts, shipping costs, etc.. |

Example:
...
</basketItems>
<links>
<link type="defaultCheckout" xlink:href="https://www.vm104.vnet/dk-dk/-C2001/Checkout/Basket/cart/basket/c64ebdad-595a-4a93-a89b-12f57d3c08d8"/>
<link type="shopCheckout" xlink:href="https://205909.vm104.vnet/dk-dk/shop/basket/cart/basket/c64ebdad-595a-4a93-a89b-12f57d3c08d8"/>
<link type="platformCheckout" xlink:href="https://www.vm104.vnet/dk-dk/-C2001/Checkout/Basket/cart/basket/c64ebdad-595a-4a93-a89b-12f57d3c08d8"/>
</links>
<shipping>
<shippingType id="1"/>

<price>
...
</price>
</shipping>
 <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>2.0</vatIncluded>
            <vatExcluded>0.38</vatExcluded>
            <vat>19.0</vat>         
         </price>      
      </discount>   
   </discounts>
   <priceItems>      
      <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/>
      <vatIncluded>12.0</vatIncluded>
      <vatExcluded>9.72</vatExcluded>
      <vat>19.00</vat>   
   <priceItems>   
   <priceTotal>
      <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/>
      <vatIncluded>10.0</vatIncluded>
      <vatExcluded>8.10</vatExcluded>
      <vat>19.0</vat>
   </priceTotal>
</basket>
{code}
| basketItem/element/properties | A list of properties that further refine the abstract element. \\ |
| basketItem/element/properties/property \\ | A property value that corresponds to the property key, e.g. size:2 or appearance:1. Properties might be different depending on the element type. Spreadshirt articles and products support size and appearance only. Properties are mandatory for basket item creations. \\ |
| basketItem/element/properties/property/@key | | appearance: 1 (Depends on the product type. Check the productType resource to determine the appearanceId) \\
size: 2 (Depends on the product type. Check the productType resource to determine the sizeId) \\
appearanceLabel: i18n name of product type appearance, e.g. Red \\
sizeLabel: i18n name of product type size, e.g. M \\
appearanceLink: link to product type appearance color image, e.g.&nbsp;[http://image.spreadshirt.net/image-server/v1/appearances/15] |
| basketItem/links \\ | list of links that belong to actions that can be executed for this basket item \\ |
| basketItem/links/link \\ | concrete link of link list \\ |
| basketItem/links/link@type \\ | link type that can be either edit or continueShopping. edit link is the link displayed in checkout for editing the basket item. continueShopping link is used in checkout as link for continue shopping button. \\ |
| basketItem/links/link@xlink:href \\ | actual URL \\ |
| basketItem/discounts | The possible discounts and the discount value per single item that applies. |
| basketItem/priceItem | The single basket item price without reductions through discounts, etc.. |
| basketItem/price \\ | The single basket item price. Price is calculated by the API. Price contains discount reductions. \\ |
| basketItem/shop \\ | In case of mixed mode basket, a reference to the shop where the customer bought the item. \\ |
| basketItem/origin | Reference to the origin of the basket. Origin can be used to tell the platform, where the basket item actually comes from, i.e. from which product or sales channel. |
<link type="continueShopping" xlink:href="http://www.yourdomain.de"/>
</links>
<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>2.0</vatIncluded>
            <vatExcluded>0.38</vatExcluded>
            <vat>19.0</vat>
         </price>
      </discount>
   </discounts>
   <priceItem>
    <currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/>
      <vatIncluded>12.0</vatIncluded>
      <vatExcluded>9.72</vatExcluded>
      <vat>19.00</vat>
   <priceItem>   
 <price>
<currency id="1" xlink:href="http://api.spreadshirt.net/v1/currencies/1"/>
<vatIncluded>10.0</vatIncluded>
<vatExcluded>9.8</vatExcluded> <vatExcluded>8.1</vatExcluded>
<vat>0.2</vat> <vat>19.00</vat>
</price>
</basketItem>
You can find more basket item examples in the [API browser application|API Browser] .

h1. Discount calculation example

* only basket item where shop and product type of article/product support discounts are considered&nbsp;
* 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. Use Cases