X-Cart: shopping cart software

X-Cart forums (https://forum.x-cart.com/index.php)
-   Dev Questions (X-Cart 5) (https://forum.x-cart.com/forumdisplay.php?f=56)
-   -   Adding order meta data and displaying it places! (https://forum.x-cart.com/showthread.php?t=76603)

NavinSeth 10-26-2018 05:22 AM

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.

tony_sologubov 10-31-2018 04:50 AM

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

Ed B. 09-22-2019 06:10 AM

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.

Ed B. 09-22-2019 06:36 AM

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.

Ed B. 09-22-2019 09:41 AM

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?

cflsystems 09-22-2019 04:15 PM

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

Ed B. 09-23-2019 10:31 AM

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?

cflsystems 09-23-2019 12:06 PM

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

Ed B. 09-24-2019 12:56 AM

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 :oops:


All times are GMT -8. The time now is 09:08 AM.

Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.