Evaluate discount promotion in Product Detail Page - sap-commerce-cloud

Scenario :
I've been trying to implement something like Amazon has on their product pages in, where the non promoted price is crossed, and the promoted price is highlighted.
I have the PROMOTIONS product option selected in the controller, and
it is returning the potencialPromotion, but it doesn't have the value
of the discount in that structure only the message (as on the
Accelerator it appears the message).
I'm in Hybris 6.6 and I looked up the DefaultPromotionEngineService.evaluate method because it is used in the Cart, and for the cart it returns the promotion actions, but the equivalent method for the product isn't returning anything.
Has anybody done this? Seems like a pretty convencional request although I know it goes against the flexibility of promotion engine.
I can use a Regex against the message to get the discount, but it's a road I don't want to take because it will end badly....
Please suggest.
Thank you

Since you haven't mentioned it before, I have answered based on Legacy Promotion, not the Promotion Engine. I'll update answer if there is a way to do the same in Promotion Engine.
It's true, OOTB there is no service which gives you the discount price on PDP.
I think what you can do,
Override PromotionsPopulator to get the discount value and set it to promotionData.
if (fixedPricePromotion instanceof ProductFixedPricePromotionModel)
{
PromotionPriceRowModel promotionPriceRowModel = ((ProductFixedPricePromotionModel)source).getProductFixedUnitPrice();
//TODO: covert promotionPriceRowModel to promotionPriceData
//TODO: set to promotionData
}
ProductPromotionsPopulator internally calls the above populator to convert ProductPromotionModel to data.

I think we can achieve this using the price row. We can create one more price row and display the logic correctly based on the discount price.

Related

SUITETALK- Netsuite searchAdvanced gives line price in base currency

Can anyone please help us with this?
We are using Netsuite advanced search to pull sales order for different subsidiary. We are able to get all the line items(except tax itmes) but its consists the amount in base currency. Is there any way we can get response with exact amount visible in UI.
Also Its very hard to understand the basic of Netsuite SUITE TALk- SOAP. Do you recommend any resources that will ease learning?
Thanks
Just an update with this question, with Advanced search we are able to get the foreign currency of Subsidiary using fxCost in columns But line items doesn't have this option. This causes whole another problem for us. Then we decided to use SAVED SEARCH. Saved search provides us feature to disable foregin currency just by choosing CONSOLIDATED EXCHANGE RATE to none. We are using saved search ID in the Advanced search paramater ie using savedSearchScriptId from Netsuite Schema.
Hope it would be helpful to anyone who is strugglign with this kind of issue.
Thanks
For tax line in fx currency, prefer to do Tax Amount/exchange rate.

updating Stripe Price object

I had a question that seems to be easy but apparently is not working. I need to update the price for a Price object, but the following does not work. It gives the error that unit_amount is not known, although we use it to define the Price object initially:
stripe.Price.modify(
"price_1Hkb5FHdAaIdH7ntvOhZOyFK",
unit_amount=10,
)
You can not modify the price of a Price in the API. This is not something that is supported as there's no corresponding parameter on the API.
If you want to change the amount associated with a Price, you would create a new Price object and start using it instead. You could also make the old one inactive for example.
Another powerful feature of Stripe's API is the lookup_key on Price (doc). This lets you define a custom alias for your Price in your code. That way instead of hardcoding the price id price_123 in your code and having to update it to use price_abcd, you can transfer the old lookup key from the old price to the new one and have your code seamlessly start using the new one automatically. The idea is that you either cache the Price id associated with a lookup key based on webhooks for example or use the List Prices API and the lookup_keys parameter to quickly find the latest price id associated with a given lookup key!

How to get Amazon's discounted price?

I'm using ItemSearch Amazon API. It works fine for most cases; however, when Amazon has a discount, it doesn't show the discounted price they show on Amazon, it returns the old original price.
For example for this item, Amazon's discounted price is $37.50. However, the API just returns the original price: $44.99.
The Offers section doesn't help either (it has other sellers' offers, not Amazon's).
Any thoughts anyone?
Here is the API call for your convenience (fill up the {} fields):
http://webservices.amazon.com/onca/xml?AWSAccessKeyId={}&AssociateTag={}&Condition=New&Keywords=887961219319&Operation=ItemSearch&ResponseGroup=Images%2CItemAttributes%2CLarge%2COffers%2CReviews&SearchIndex=All&Service=AWSECommerceService&Timestamp={}&Signature={}
After almost about a week of digging and investigation, it turns out I had to remove the "condition" field from the request! After that, I was able to get the the price displayed on Amazon.com properly! (using the filed Item.Offers.Offer.OfferListing.Price.Amount).
Reason: it seems Amazon displays what they call as "Buy Box Winner" price if it exists, or the lowest possible offer. To get this value returned in the response, you'd have to remove the Condition field in addition to the MerchantId as well. More details here.
Jeez Amazon! I hope someone finds this useful!

Event Sourcing - where does Domain Logic fit in?

I've just been watching Greg Youngs talk on Event Sourcing, but i'm confused as to where business logic fits in. A simple example:
1) Shopping Cart Created
2) Item Added
3) Item Added
4) Promotional Code - 20% Off
Is the Promotional Code calculated against the shopping carts items and the result of that stored as an event. I understand "PromotionalCodeAddedEvent" would maybe make sense, but where does the math happen? I'm thinking:
public void AddPromotionalCode(PromotionalCode code)
{
//perform calculation against shopping cart items.
//if valid
ApplyChanges(cmd);
}
Then the result doesn't end up anywhere and the Read Model would have to perform the calculations.
I'm not fully understanding the concept, any help would be great.
Something as seemingly simple as a promotional code can actually be a fairly complex use case. Primarily, this is due to the fact that a promotional code is logic that (usually) is maintained by one or more business users, whereas it also belongs inside of the domain, itself. It is non-traditional, in that sense. There are multiple ways to handle this, and what I will outline would just be my personal approach.
For the sake of argument, assume that you have a simple series of known promotional codes, such as:
X% Off Purchase, with or without a Minimum Purchase
$X Off Purchase, with or without a Minimum Purchase
We can make some assumptions, as well:
A Promotional Code has a Start Date
A Promotional Code has an End Date
The application of a promotional code can be tricky. Consider the two scenarios that we have defined. "$X Off Purchase" is comparatively simple, because it is a fixed amount. "X% Off Purchase", however, is more complex. If we only had the fixed amount, we could apply the discount to the cart as soon as any thresholds are met. With a percentage-based discount, if the user were to add two items, add a promotional code, and then add another item, the promotion would have already been "applied".
Because of this, I would personally only "attach" a promotional code to a cart. Why? The reason is that at the point of checkout, I can likely assume that a cart is going to be used to generate an order. Until that time, the cart's contents are fluid. A user's action against the cart will change the total value of the cart, as well as the total discount, assuming a non-fixed discount amount. It can also render either discount as being invalid, should a user remove one or more items from a cart and the total value of the cart fall below the threshold to apply the discount.
So, I would actually have multiple commands which would would be involved. Essentially any commands that impact the value of the cart could change the discount amount. To that end, I would be looking for the discount amount to be recalculated for the commands which:
Add an item to the cart
Remove an item from the cart
Change the quantity of items in the cart
Add a promotional code to the cart
Change the promotional code attached to the cart
Since these all are operations against a cart, I would be calculating the discount within the promotional code, itself, with the participation of the data contained in the cart. It feels like a promotional code is going to be an aggregate, going down this path. So, I would have the command handlers invoke a domain service that can provide my cart with the information that it requires. That domain service is going to load the promotional code, and I am going to be able to pass in the line items within that cart, so that the promotional code will tell me what the calculated discount would be. Then, I am going to generate the event, which contains the new value of the cart, along with the adjusted value (the discount). Going down this path, the logic for calculating a discount based upon line items within a cart is the responsibility of the promotional code.
You could put this responsibility in the cart, instead. Personally, though, I feel as if encapsulation of domain logic within the promotional code, itself, makes more sense. I had mentioned that it is likely that you will generate an order from a cart. By having the promotional code as an aggregate, and it containing the logic to apply the discount based upon the line items, we have a single truth, in how we calculate a discount for line items - whether that is in terms of a cart or in terms of an order.
You can, for example, raise a second event such as PromotionalCodeApplied which contains the computation results.
The Read Model then just have to use the pre-computed result.
I understand "PromotionalCodeAddedEvent" would maybe make sense, but where does the math happen?
It should happen in commands that perform modifications to the shopping cart. Every such command will call some method like RecalculateTotals() where all business logic will be hosted.
Consider the following pseudocode:
public void AddPromotionalCode(PromotionalCode code)
{
var #event = new PromotionalCodeAdded(code);
var amount = RecalculateTotalAmount(extraEvent: #event);
#event.TotalAmount = amount;
_eventStore.Publish(#event);
}
decimal RecalculateTotalAmount(IEvent extraEvent)
{
var relatedEventTypes = new[] { typeof(PromotionalCodeAdded), typeof(ShoppingCartCreated), typeof(ItemAdded) };
var events = _eventStore.ReadEventsOfTypes(relatedEventTypes);
var events = events.Concat(new[] { extraEvent });
//calculation logic goes here based on all related events
}
This is where I like to return events from command methods. As Alexander Langer mentioned, you'd apply the "math" and return the relevant event(s):
public PromotionalCodeApplied AddPromotionalCode(PromotionalCode code)
{
//perform calculation against shopping cart items.
var promotionalCodeApplied = new PromotionalCodeApplied(code.VoucherNumber, discountAmount, DateTime.Now);
On(promotionalCodeApplied);
return promotionalCodeApplied;
}
public void On(PromotionalCodeApplied promotionalCodeApplied)
{
_voucherNumber = promotionalCodeApplied.VoucherNumber;
_discountAmount = promotionalCodeApplied.DiscountAmount;
_discountDate = promotionalCodeApplied.DateAppllied;
}
Now your read model has access to the relevant values.

Amazon MWS Api usage

I am using "http://www.amazon.de/dp/{ASIN}" to get product info.
But after getting response it doesn't return product "SellerSKU"
Is there any way that I can get "SellerSKU" of a product specified by "ASIN"?
I also had same situation.
And I found that there is only some limited way to get it.
https://mws.amazonservices.com/FulfillmentInventory/2010-10-01?Action=ListInventorySupply
ListInventorySupply api of Fulfillment Inventory lists returns information about the availability of a seller's inventory.
Request parameter includes SellerSKUs, QueryStartDateTime, MarketplaceId, ResponseGroup
Here you can omit SellerSKUs, and you can pass QueryStartDateTime.
Then you will get InventorySupplyList including SellerSKU and ASIN matches.
You should find the product's SellerSKU in this list.
But the problem is that it returns only available inventory list.
It will not work when product you are finding is not in available inventory list.
In this case you should make the user manually add SellerSKU in your application.
For more information, please take a look at http://docs.developer.amazonservices.com/en_US/fba_inventory/FBAInventory_ListInventorySupply.html
Hope this would help you.

Resources