Follow us on Twitter X-Cart on Facebook Wiki
Shopping cart software Solutions for online shops and malls

Adding order meta data and displaying it places!
 
Reply
   X-Cart forums > X-Cart 5 > Modifying the design and features (X-Cart 5)
 
Thread Tools Search this Thread
  #1  
Old 10-26-2018, 05:22 AM
 
NavinSeth NavinSeth is offline
    
Join Date: Oct 2018
Posts: 1
 

Default Adding order meta data and displaying it places!

I currently have the following scenario and need some guidance.

I would like to add a piece of meta data to an order when it is created and include that data on the invoice template for the order. For argument sake let's call this data orderColor.

1) How do I create a new column to the gbxc5_orders table? (orderColor column).
2) How do I populate orderColor when the order is created?
3) How do I show the orderColor on the invoice when a admin user views the order AND when the invoice is emailed on order creation event?
4) How do I show the orderColor column on the packing slip?

Any guidance would really be appreciated!

Thank you.
Reply With Quote
  #2  
Old 10-31-2018, 04:50 AM
  tony_sologubov's Avatar 
tony_sologubov tony_sologubov is offline
 

X-Cart team
  
Join Date: Jan 2009
Posts: 2,428
 

Default Re: Adding order meta data and displaying it places!

Hi Navin,

Thanks for choosing X-Cart and welcome to X-Cart forums!

Quote:
Originally Posted by NavinSeth
I currently have the following scenario and need some guidance.

I would like to add a piece of meta data to an order when it is created and include that data on the invoice template for the order. For argument sake let's call this data orderColor.

1) How do I create a new column to the gbxc5_orders table? (orderColor column).

The process of adding a new property to the model is described here:
https://devs.x-cart.com/basics/adding_new_property_to_a_product/#decorating-model-class

This example is for \XLite\Model\Product class, but you can decorate \XLite\Model\Order class all the same. Although, you will be adding orderColor property instead of myMessage.

Quote:
2) How do I populate orderColor when the order is created?

\XLite\Model\Order class has the processSucceed() method that is run when you place an order. You should decorate it and put the code of defining processSucceed property there.

Quote:
3) How do I show the orderColor on the invoice when a admin user views the order AND when the invoice is emailed on order creation event?
4) How do I show the orderColor column on the packing slip?[/quote]

These tasks are similar to one described here: https://devs.x-cart.com/design_changes/adding_product_images_to_order_notifications.html

Please, have a look at the article and you find any difficulties, please let me know.

Tony
__________________
Found a bug in X-Cart? Post it to our bug tracker!
Know how to make X-Cart better? Suggest an idea!
Reply With Quote
  #3  
Old 09-22-2019, 06:10 AM
 
Ed B. Ed B. is online now
 

eXpert
  
Join Date: Apr 2016
Posts: 220
 

Default Adding a property to the model "Order"

Quote:
Originally Posted by tony_sologubov

The process of adding a new property to the model is described here:
https://devs.x-cart.com/basics/adding_new_property_to_a_product/#decorating-model-class

This example is for \XLite\Model\Product class, but you can decorate \XLite\Model\Order class all the same. Although, you will be adding orderColor property instead of myMessage.



I have tried this, with model class Vendor/ModuleID/Model/Order.php
Code:
<?php namespace XLite\Module\Vendor\ModuleID\Model; abstract class Order extends \XLite\Model\Order { /** * @Column (type="string") */ protected $quotestatus = ''; public function getQuotestatus() { return $this->quotestatus; } public function setQuotestatus($value) { $this->quotestatus = $value; return $this; } }
with the error
Code:
X-Cart rebuild step failed Step failed with the following errors:
  • Class "XLite\Module\Vendor\Module\Model\Order" sub class of "XLite\Model\Order" is not a valid entity or mapped super class
What am I doing wrong here? I also tried without "abstract" with the same result.
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
  #4  
Old 09-22-2019, 06:36 AM
 
Ed B. Ed B. is online now
 

eXpert
  
Join Date: Apr 2016
Posts: 220
 

Default Re: Adding order meta data and displaying it places!

By the way, the above happens with x-cart 5.4. With x-cart 5.3, I don't get the errors, but I still don't have the new properties.
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
  #5  
Old 09-22-2019, 09:41 AM
 
Ed B. Ed B. is online now
 

eXpert
  
Join Date: Apr 2016
Posts: 220
 

Default Re: Adding order meta data and displaying it places!

OK, a solution was indicated in the thread https://forum.x-cart.com/showthread.php?t=76244
but adding a line
Code:
/** * @Decorator\Depend("XLite\Model\Order")*/
doesn't solve the issue. Any idea?
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
  #6  
Old 09-22-2019, 04:15 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 13,592
 

Default Re: Adding order meta data and displaying it places!

You are not decorating the class?
Look at the XLite\Model\Order class annotations before the class declaration. There's probably MappedSuperclass and you need to have it in your new class as well
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote
  #7  
Old 09-23-2019, 10:31 AM
 
Ed B. Ed B. is online now
 

eXpert
  
Join Date: Apr 2016
Posts: 220
 

Default Re: Adding order meta data and displaying it places!

Well, the class annotations for \XLite\Model\Order looks like (for X cart 5.4.0.4)

Code:
namespace XLite\Model; use Doctrine\Common\Collections\ArrayCollection; use Doctrine\DBAL\LockMode; use Doctrine\ORM\EntityManager; use XLite\Core\Database; use XLite\Model\Payment\Transaction; /** * Class represents an order * * @Entity * @Table (name="orders", * indexes={ * @Index (name="date", columns={"date"}), * @Index (name="total", columns={"total"}), * @Index (name="subtotal", columns={"subtotal"}), * @Index (name="tracking", columns={"tracking"}), * @Index (name="payment_status", columns={"payment_status_id"}), ... * } * ) * * @ClearDiscriminatorCondition * @HasLifecycleCallbacks * @InheritanceType ("SINGLE_TABLE") * @DiscriminatorColumn (name="is_order", type="integer", length=1) * @DiscriminatorMap ({1 = "XLite\Model\Order", 0 = "XLite\Model\Cart"}) */ class Order extends \XLite\Model\Base\SurchargeOwner
What should I put in my Order class?


By the way, the Model\Product class that I seem to be able to decorate, has annotations like
Code:
namespace XLite\Model; use XLite\Core\Cache\ExecuteCachedTrait; use XLite\Core\Model\EntityVersion\EntityVersionInterface; use XLite\Core\Model\EntityVersion\EntityVersionTrait; use XLite\Model\Product\ProductStockAvailabilityPolicy; use Doctrine\Common\Persistence\Event\LifecycleEventArgs; /** * The "product" model class * * @Entity * @Table (name="products", * indexes={ * @Index (name="sku", columns={"sku"}), * @Index (name="price", columns={"price"}), * @Index (name="weight", columns={"weight"}), * @Index (name="free_shipping", columns={"free_shipping"}), * @Index (name="customerArea", columns={"enabled","arrivalDate"}) * } * ) * @HasLifecycleCallbacks */ class Product extends \XLite\Model\Base\Catalog implements \XLite\Model\Base\IOr derItem, EntityVersionInterface


Where are the differences?
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
  #8  
Old 09-23-2019, 12:06 PM
  cflsystems's Avatar 
cflsystems cflsystems is offline
 

Veteran
  
Join Date: Apr 2007
Posts: 13,592
 

Default Re: Adding order meta data and displaying it places!

Probably HasLifecycleCallbacks
But again you are not decorating the class. You are creating new class based on Model\Order so the actual Model\Order class will not have your new properties.


You need define it as


abstract class Order extends \XLite\Model\Order implements \XLite\Base\IDecorator


in order to decorate the Model\Order class and see your new properties there
__________________
Steve Stoyanov
CFLSystems.com
Web Development
Reply With Quote

The following user thanks cflsystems for this useful post:
Ed B. (09-24-2019)
  #9  
Old 09-24-2019, 12:56 AM
 
Ed B. Ed B. is online now
 

eXpert
  
Join Date: Apr 2016
Posts: 220
 

Default Re: Adding order meta data and displaying it places!

Quote:
Originally Posted by cflsystems
Probably HasLifecycleCallbacks
But again you are not decorating the class. You are creating new class based on Model\Order so the actual Model\Order class will not have your new properties.


You need define it as


abstract class Order extends \XLite\Model\Order implements \XLite\Base\IDecorator


in order to decorate the Model\Order class and see your new properties there




Of course! How stupid was I, somehow I had deleted that part trying to debug (there were typos in other places) and didn't think about put it back again
__________________
X-cart 5.2.12, php 5.6
Ed from Grenoble, France
Reply With Quote
Reply
   X-Cart forums > X-Cart 5 > Modifying the design and features (X-Cart 5)


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump


All times are GMT -8. The time now is 05:19 AM.

   

 
X-Cart forums © 2001-2018