Developer forum

Forum » Development » Custom module - insert prices into priser module

Custom module - insert prices into priser module

Vilius Janulis
Reply
 Hi,

I need to make somehow that product would have few prices depending on the amount of products.
What i though is to insert prices with name(definition,title) as amount and price as price into priser module.

Code example i have tried :
"
 
                        try
                        {
                            Dynamicweb.eCommerce.Prices.Price pr10 = new Dynamicweb.eCommerce.Prices.Price();

                            pr10.Quantity = Base.ChkDouble(productInterval10);
                            pr10.Amount = Base.ChkDouble(productPrice10);
                            pr10.AmountString = Base.ChkString(productPrice10);
                            pr10.ID = p.ID + "quantity" + pr10.Quantity + "price" + pr10.Amount;
                            pr10.Save(pr10.ID, p.ID, "DKK");

                            p.Prices.Add(pr10);
                        }
                        catch (Exception e)
                        {
                            ScriptStuff.AppendLine(e.Message);
                        }
 
"

And i did not got any exception, but the prices was not added too.
How to make it ? 
How to use bulk prices ?


Thank you.

Replies

 
Morten Snedker
Reply
 Hi Vilius,

Bulk prices is the way to go and you are on right track! I think the only thing that you're missing out on, is setting the LanguageID of the Price object. That in place it ought to work.

How it should look in the backend, clicking the "Prices" button of a product:



The data goes to table EcomPrices, which you may also use for validation.
 
Let me know if you're having succes!

Regards /Snedker



 
Vilius Janulis
Reply
It did not worked.

Tried few more of these, by defining different values did not worked, even though in the database it looks the same as created manually in back end.
Where in the database the bulk prices names (titles) are stored ? Because the EcomPrices table dont have these values (for example) 6,12,24.
Unless you have some other suggestions i could try to make it throughout sql query.

Does it needs some kind of bulk prices assignment to the product except the one i wrote above ?

Thank you.
 
Morten Snedker
Reply
 Hi Vilius,

This is a working example, that ought to get you going. It creates three bulk prices on one product (on pageload to make it a quickie):

using Dynamicweb;
using Dynamicweb.Frontend;
using Dynamicweb.Extensibility;

namespace Extensibility
{
    [Subscribe(Dynamicweb.Notifications.Standard.Page.Loaded)]
    public class NotificationSubscriber1 : NotificationSubscriber
    {
        public override void OnNotify(string notification, object[] args)
        {
            if (Base.Request("doprices") == "true")
            {
                Dynamicweb.eCommerce.Products.Product product = new Dynamicweb.eCommerce.Products.Product("990002@SHOP1", "", "LANG1");
                Dynamicweb.eCommerce.Prices.Price price = new Dynamicweb.eCommerce.Prices.Price();

                //6 bottles, 70 á pcs
                price.Amount = 70;                      //price
                price.Quantity = 6;                     //amount of products
                price.ProductID = product.ID;
                price.CurrencyCode = string.Empty;      //empty = default currency. Otherwise just set it.
                price.LanguageID = product.LanguageID;
                price.Save(price.ID, price.ProductID, price.CurrencyCode);

                product.Prices.Add(price);

                // 12 bottles, 60 á pcs
                //making a new instance will atomatically generate new PriceID (but you may set it yourself)
                price = new Dynamicweb.eCommerce.Prices.Price(); 
                price.Amount = 60;
                price.Quantity = 12;
                price.ProductID = product.ID;
                price.CurrencyCode = string.Empty;
                price.LanguageID = product.LanguageID;
                price.Save(price.ID, price.ProductID, price.CurrencyCode);

                product.Prices.Add(price);


                // 24 bottles, 35 á pcs
                price = new Dynamicweb.eCommerce.Prices.Price();
                price.Amount = 35;
                price.Quantity = 24;
                price.ProductID = product.ID;
                price.CurrencyCode = string.Empty;
                price.LanguageID = product.LanguageID;
                price.Save(price.ID, price.ProductID, price.CurrencyCode);

                product.Prices.Add(price);
                product.Save(product.ID, product.VariantID, product.LanguageID);
            }
        }
    }
}

Please let me know if it works for you.

Regards /Snedker
 
Vilius Janulis
Reply
 Did not worked ether...

Even thought code is almost exactly the same..
Noticed some overloads changed , this solution version :

my code :    19.2.5.2                                 

 try
                        {
                            if (productInterval1 != "0" && productInterval1 != "")
                            {
                                Dynamicweb.eCommerce.Prices.Price pr1 = new Dynamicweb.eCommerce.Prices.Price();

                                pr1.Quantity = Base.ChkDouble(double.Parse(productInterval1));
                                pr1.Amount = Base.ChkDouble(double.Parse(productPrice1));
                               // pr1.AmountString = Base.ChkString(productPrice1);
                                pr1.LanguageID = p.LanguageID;
                                pr1.ProductID = p.ID;
                                pr1.CurrencyCode = string.Empty;
                               // pr1.CurrencyCode = "DKK";
                                pr1.Save(pr1.ID, p.ID, pr1.CurrencyCode);
                               //pr1.Save(pr1.ID, pr1.PeriodID, pr1.CurrencyCode);

                                p.Prices.Add(pr1);
                            }
                        }
                        catch (Exception e)
                        {
                            ScriptStuff.AppendLine(e.Message);
                        }

Maybe you could tell me where quantity is stored in the database for this priser module ?



The hole sequence is find get values, find product, add values to product, nothing specials and it does not work for me.
 
Morten Snedker
Reply
Quantity goes to column PriceQuantity of table EcomPrices.

Make sure you actually have a value in p.ID of the Save() method.

/Snedker
 
Vilius Janulis
Reply
 Ok how i have not see it...


But even with sql i does not work !!! Even though the lines in database look 100% same as if i add these prices manually ..
Since it work when i add manually i assume that module works as should.
So why i am not able to add these prices in custom module ... ?

Do other tables then EcomPrices are affected with this module ?
Do i really dont need to assign bulk prices (Flerstykspriser) 'group' to the product somehow ? 

Attached how everything looks ...

Have tried to change PriceID if it has effect, also as we talked before tried to make it completely with API, so ids was correct ones ... Did not worked...


Any new ideas ?

By the way thank you for your help!
db.png db_added_manually.png priser.png
 
Morten Snedker
Reply
Could you please provide the entire method/class where you have your code. I need to see it in context.

/Snedker
 
Vilius Janulis
Reply
 Yes of course.

Just the class file, should be enough, if not let me know.
Hope it is not to confusing.

Basically it is custom module to transfer products from shop to eCommerce with variants.

Thank you. 
 
Vilius Janulis
Reply
Good morning Morten.

Once again Thank you for you help.
Just wondering maybe you had time to look at it and have any other suggestions?

I am out of ideas, it should show in the backend since they are exactly the same as created manually in the database but they do not.

 
Morten Snedker
Reply
 Hi Vilius,

Could you provide me the file being imported?

Regards /Snedker
 
Vilius Janulis
Reply
 It is not a file it is database .. the same one as DW is in. It is transfer from old DW 'Shop' module to new DW 'eCommerce' module
 
Vilius Janulis
Reply
 It is shown in the file i have attached. 
But as i said all values are correct i have checked the database after import, their were identical .. so import work, just the backend does not show them..

Any ideas ?
 
Morten Snedker
Reply
 What is the URL of the site you're testing this on?
 
Vilius Janulis
Reply
 http://display2011.net.dynamicweb.dk/Admin/default.aspx
 
Vilius Janulis
Reply
 Hey Morten,

Do you have any suggestions how to make this work ?

If it does not use any other tables in database maybe it is dw version (wrote above) bug for this module or etc ?
The database is for sure correct one, the data in table is correct, tried two different ways api, sql... dont know what else could be here ...
Do you ? Any thought would be worth to check :)
 
Morten Snedker
Reply
This post has been marked as an answer
We we missed out on some product properties:

product.PriceCnt = 3; //the number of different bulks
product.PriceMatrixMultiplePrices = 1;  //true - yes, we have bulk prices
product.PriceMatrixQuantitySpecification = "6;12;24"; //a list of bulk quantities (in this case 6, 12 and 24 pcs.
product.Save(product.ID, product.VariantID, product.LanguageID);
So it is the three lines before the Save() you need to set. That is why you don't have the prices shown in backend.
 
Let me know if it works for you.

/Snedker
 
 
Votes for this answer: 0

 

You must be logged in to post in the forum