Developer forum

Forum » Ecommerce - Standard features » EcomPrices, not all fields are saved using the API

EcomPrices, not all fields are saved using the API

Martijn Bokhove
Reply

We are using real time calls for getting the prices to show and use in the shop.
The prices must be added/updated in the EcomPrices, so DynamicWeb can use these prices.

Using the API, not all fields are filled in the database. While the fields are filled when debugging the code.
The next fields (we are using) do not get filled using the API:
-PriceShopID
- PriceValidFrom
- PriceValidTo
- PriceUserID <- our most important

The normal API function is used:

Dim custPrice As Price = New Price
custPrice.Amount = prodPrice
custPrice.ProductID = prodId
custPrice.Quantity = 1
custPrice.LanguageID = "LANG1"
custPrice.CurrencyCode = "EUR"
custPrice.ShopID = "SHOP1"
custPrice.UserID = userId
custPrice.User.ID = userId
custPrice.User.UserName = u.UserName
custPrice.UserCustomerNumber = u.CustomerNumber
custPrice.VariantID = variantId
custPrice.ValidFrom = Now.AddHours(-1)
custPrice.ValidTo = Now.AddYears(1)
_pricesToSave.Add(custPrice)
For Each newPrice As Price In _pricesToSave
    newPrice.Save(newPrice.ID, newPrice.ProductID, newPrice.CurrencyCode)
Next

We tried several options to get the UserID filled, but without succes.


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Martijn,

If I understand you correctly, you need to provide real time / live prices for your different users while they're looking at products and flowing through the cart. If this is so, you should not try and change the values in the database, rather implement a price provider to provide the different prices.

You can read more about price providers here: http://developer.dynamicweb-cms.com/documentation/for-developers/ecommerce/extensibility/providers/price-providers.aspx

Hope this helps :)

- Jeppe

Votes for this answer: 1
 
Martijn Bokhove
Reply

Hi Jeppe

Thanks for your reply.
Indeed, it is realtime information from an external service.

If the dynamic prices will be used in the cart also, that's a better way to implement than I did now.
Will give it a try with your example.

Thanks again.

Gr.
Martijn
 

 
Martijn Bokhove
Reply

Hi Jeppe

Is it also possible to call the PriceProvider after loading a page?
The problem we have is that it takes a couple of seconds before the external service sends back the information. If we can load the prices after the pageload is complete, the visitor doesn't have to wait for the complete page.

Also running some test with the PreparePrices, but the function doesn't get called in 8.4.1.+ ?
I have placed the code next to the FIndPrice, and also in a seperate file. The FindPrice gets called everytime, PreparePrices never?

Gr
Martijn

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

It's not possible to load prices after the page has loaded. At that time, it's too late to influence the content on the page. If your external service is that slow, you should consider either caching or doing this as imports that run at specific intervals instead.

We have not changed anything related to the price provider concept for 8.4.1, so PreparePrices should still be invoked. Which of the PreparePrices overloads do you override?

- Jeppe

 
Martijn Bokhove
Reply

I used it inside the PriceProvider:

Public Class CustomDiscountPriceProvider
    Inherits PriceProvider
 
    Public Overrides Sub PreparePrices(products As ProductCollection)
        ' Fetch prices from the external system using a mock connector

Could it be added somewhere else?

Gr.
Martijn

 

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

You have to have both pieces code inside the same class that inherits from PriceProvider in order to override prices.

You need to override the FindPrice method and -- in your case -- one of the PreparePrices methods, specifically the one that accepts a ProductCollection as argument, NOT the one that takes a Dictionary.

If this does not work, i.e., the PreparePrices method is not being invoked, I'll have to check up on that. Just remember that there are two different PreparePrices overloads, and you need the correct one.

- Jeppe

 

You must be logged in to post in the forum