logo
Welcome to our new AbleCommerce forums. As a guest, you may view the information here. To post to this forum, you must have a registered account with us, either as a new user evaluating AbleCommerce or an existing user of the application. For all questions related to the older version of Gold and earlier, please go to AbleCommerce Gold forum. Please use your AbleCommerce username and password to Login. New Registrations are disabled.

Notification

Icon
Error

Options
Go to last post Go to first unread
Joe Payne2  
#1 Posted : Monday, May 10, 2021 8:15:45 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
When I look at the code for the .Copy() method on the Order entity, I see a few problems. No UserId assigned, no options for including shipments, items, notes etc. And the order number will immediately become a duplicate order number.

is there anything better?

Code:

        /// <summary>
        /// Create a shallow copy of this Order instance.
        /// </summary>
        /// <returns>A copy of this instance.</returns>
        public virtual Order Copy()
        {
            return new Order(this.OrderNumber, this.OrderDate, this.Store, this.BillToFirstName, this.BillToLastName, this.BillToCompany, this.BillToAddress1, this.BillToAddress2, this.BillToCity, this.BillToProvince, this.BillToPostalCode, this.BillToCountryCode, this.BillToPhone, this.BillToFax, this.BillToEmail, this.OrderStatus, this.Exported, this.RemoteIP, this.Referrer, this.GoogleOrderNumber);
        }

Wanna join the discussion?! Login to your AbleCommerce Forums forum account. New Registrations are disabled.

mazhar  
#2 Posted : Tuesday, May 11, 2021 1:57:39 AM(UTC)
mazhar

Rank: Administration

Groups: Admin, Administrators, HelpDesk, System, Authorized User, Developers, Registered
Joined: 10/5/2018(UTC)
Posts: 175

Thanks: 8 times
Was thanked: 17 time(s) in 15 post(s)
This is a shallow copy method which mean that it will only copy the direct fields of the object and not the related data in associated objects. What you can do is that you can create a shallow copy and then copy the required associations before saving copied object. For order number you can set the new order number by querying the next order number.
Joe Payne2  
#3 Posted : Tuesday, May 11, 2021 7:15:31 AM(UTC)
Joe Payne2

Rank: Advanced Member

Groups: HelpDesk, Developers
Joined: 11/9/2018(UTC)
Posts: 564

Thanks: 122 times
Was thanked: 26 time(s) in 25 post(s)
I can of course do all of that. But as written, that method will cause many more problems than it solves which is my point. The Copy() needs to work properly, or it should be removed.
Users browsing this topic
Guest (2)
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.