Developer forum

Forum » Ecommerce - Standard features » Bug in the Dynamicweb.Ecommerce.Orders.Order.DowngradeToCart() Method

Bug in the Dynamicweb.Ecommerce.Orders.Order.DowngradeToCart() Method

Alexander P.
Reply

Here is a decompiled version of the method (please be advised, that original variable names might have gotten lost in the compilation process):

// Dynamicweb.eCommerce.Orders.Order
public void DowngradeToCart()
{
    string id = this.ID;
    string number = NumberGenerator.GetNumber("CART");
    Database.ExecuteNonQuery(string.Format("UPDATE EcomOrders SET OrderID = '{0}', OrderCart = {1} WHERE OrderID = '{2}'", number, Database.SqlBool(true), id), "Ecom.mdb");
    this.ID = number;
    this.IsCart = true;
    Database.ExecuteNonQuery(string.Format("UPDATE EcomOrderLines SET OrderLineOrderID = '{0}' WHERE OrderLineOrderID = '{1}'", number, id), "Ecom.mdb");
    this._OrderLines = null;
    Dictionary<stringobject> dictionary = new Dictionary<stringobject>();
    dictionary.Add("OrderID", id);
    dictionary.Add("OrderCart"false);
    Database.CopyRow(string.Format("SELECT * FROM EcomOrders WHERE OrderID = '{0}'", number), dictionary);
    foreach (OrderLine current in this.OrderLines)
    {
        Dictionary<stringobject> dictionary2 = new Dictionary<stringobject>();
        dictionary2.Add("OrderLineID", NumberGenerator.GetNumber("OL"));
        dictionary2.Add("OrderLineOrderID", id);
        Database.CopyRow(string.Format("SELECT * FROM EcomOrderLines WHERE OrderLineID = '{0}'", current.ID), dictionary2);
    }
}

What the method does: The method apparently changes the id of the order to a cart id and all of its order line order ids to point to the new cart id and sets the order's OrderCart field in the DB to true (or 1). Afterwards, it copies the current order and all its order lines to the old (and now unoccupied) order id and sets the copied order's OrderCart field in the DB to false (or 0).

The problem: However, as you can probably see, the OrderLineParentLineID field in the DB is not being updated when downgrading the order to a cart, which means that any copies of child order lines (usually all product discount order lines) will still point to the parent order lines from the copied order.

My suggestion: I suggest changing the method, so it will first generate the sequential ID numbers for each copied order line before saving any of the copies. Then it should save each order line by taking care to save the parent order lines before their child order lines, and also take care update the parent line id field to the new id of its parent order line. And please, do this whole process in a database transaction (and hopefully using prepared statements instead) (if your API can let you do that).

Thank you for reading.

Alex


Replies

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply

Hi Alex,

I've created a bug report for this. It will probably not be fixed with the release of Dynamicweb 8.5, but in a later hotfix/service release. Once a fix is ready, we will let you know in this thread.

The tracking number is 15401.

- Jeppe

 
Adrian Ursu
Reply

Hi Jeppe,

Can I suggest that while you're at it, maybe you can also improve the Edit Order functionality.

This is something that we were asking since started to work with DW and we did not had any luck so far. The current Edit Order functionality does not allow to add products to an existing order nor change anything that will end up in a bigger value for the order. It's like it's not even a proper functionality. If you can only subtract from order, it's counter productive since you end up selling less :)

I understand the challenges of this change, but maybe it's gonna be easier if you investigate it in relation to the subject of this thread.

Thanks,

Adrian

 
Nicolai Høeg Pedersen
Reply

Hi Adrian

These 2 issues do not have much in common.

The reason why an order cannot be edited to give a higher value, is that the order is authorized against a payment provider using the order amount. If the value of the order increases to an amount over this value, we cannot capture the new amount. It would require a re-authorize. And to do a re-authorize, we would need to store credit card information which again would require a lot of certification of software, solution implementation, owner of website and the hosting facility (PCI Compliance).

But we could enable editing of orders to a higher amount, and then just not be able to collect the new amount...?

Nicolai

 
Nicolai Høeg Pedersen
Reply

We have TFS#15079 that will give you an option to enable this. Scheduled for 8.5.1, but not confirmed.

 
Adrian Ursu
Reply

Hi Nicolai,

In Romania the percentage of online payments is less than 5%. That's mostly because the shops do not carry stocks and customers are not sure that the product will be delivered. I assume that's not the case with the rest of Europe.

If you can limit the edit capability to orders that are paid by credit card, then it would solve our problem. The rest of the orders will be fully editable.

Or maybe a checkbox in the settings area and we can decide if we let them edit orders or not.

Thanks a lot,


Adrian

 
Adrian Ursu
Reply

Thanks a lot. It's better than nothing :)

 

You must be logged in to post in the forum