What event fires when cart data moves to order?

  • Posts: 64
  • Thank you received: 0
11 years 2 months ago #124392

-- HikaShop version -- : 2.2.1
-- Joomla version -- : 3.0.4

I am in a situation where I need to add custom data in order_product table.I need to know how can I add custom product details when order is created from cart data.

Thanks,

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 2 months ago #124422

You can implement the trigger onBeforeOrderCreate(&$order) where the $order object contains all the info of the order including an array of the products data that will be saved in order_product and which can be accessed with $order->products.

The following user(s) said Thank You: irfanhanfi

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 0
11 years 2 months ago #124529

I have your solution.Is it possible to save data without writing sql insert/update query.

I tried this-

public function onBeforeOrderCreate(&$order,&$do){
		if(property_exists($order,'cart')){
			if(!empty($order->cart->products)){
				foreach($order->cart->products as &$product){
					$product->customfield= 'test';
				}
			}			
		}		
	}

But customfield column is blank.

Thanks,

Please Log in or Create an account to join the conversation.

  • Posts: 26158
  • Thank you received: 4028
  • MODERATOR
11 years 2 months ago #124549

Hi,

Do you right have an item custom field with the namekey "customfield" ?
The orderProduct class filters the data stored in the "cart products" during the save, so your custom field have to exists and be accessible in the front-end.

Regards,


Jerome - Obsidev.com
HikaMarket & HikaSerial developer / HikaShop core dev team.

Also helping the HikaShop support team when having some time or couldn't sleep.
By the way, do not send me private message, use the "contact us" form instead.

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 0
11 years 2 months ago #124580

I have customfield column only in order_product table.Do I need to create column in cart_product table as well?
Also I am not sure about accessibility how can we define that?

Regards,

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 2 months ago #124602

Hi,

What Jerome says is that this method will only work if you already created a custom field of the table "item" via the menu Display->Custom fields as the system only saves the columns that are either there by default or registered as custom item fields.
Note that this requires the Business edition.

If you don't have the Business edition, then, you need to do the query yourself in the onAfterOrderUpdate function and add the data directly for the order in the database.

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 0
11 years 2 months ago #124694

I created custom fields for item but not sure why it's not saving the data.I have used queries to update cart column.

But now I need to update product price.As per requirement I have a price field in product table and I need to use that value.Is there any trigger for cart similar to onBeforeCalculateProductPriceForQuantityInOrder.Or Is there any easy way to change the cart product price?

Regards,

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 2 months ago #124732

The price of the product in the cart can be changed with a quantity price calculation override:
www.hikashop.com/support/documentation/6...tation.html#override
You can find an example here:
demo.hikashop.com/index.php?option=com_hikashop&ctrl=product&task=show&cid=214

The following user(s) said Thank You: irfanhanfi

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 0
11 years 1 month ago #126167

I have used onAfterOrderCreate( &$order,&$send_email) event and I thought this will have order_product_id but it's not there.Is there any way to get order_product_id in $order?

[cart] => stdClass Object
        (            
[products] => Array
                (
                    [0] => stdClass Object
                        (
                            [product_id] => 1
                            [order_product_quantity] => 3
                            [order_product_name] => Test Product
                            [cart_product_id] => 254
                            [cart_product_option_parent_id] => 0
                            [order_product_code] => Test_Product
                            [order_product_price] => 10.00000
                            [order_product_wishlist_id] => 0
                            [product_subscription_id] => 1
                            [order_product_tax] => 0
                            [order_product_options] => 
                            [order_product_tax_info] => Array
                                (
                                )

                            [order_product_shipping_id] => 4@0
                            [order_product_shipping_method] => manual
                        )
   )
)

I need to update hikashop_order_product table using query.But not getting the way to do so.

Thanks,

Last edit: 11 years 1 month ago by irfanhanfi.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 1 month ago #126194

Hi,

Thanks to check if the $cart_product_id is not corresponding to the order_product_id, if it is not, you can get the order_product_id with a simple query based on the order_product_code.

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 0
11 years 1 month ago #126202

Thanks ,but I cannot query based on product_code.I have to break single product to multiple based on product quantity.If user has selected 5 quantity of a product I need to break that into 5 different rows of product order.

Is there any alternative or any code changes that can help?

Thanks,

Last edit: 11 years 1 month ago by irfanhanfi.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
11 years 1 month ago #126233

You can do like that to load the whole order data:

$class = hikashop_get('class.order');
$orderData = $class->loadFullOrder($order->order_id);
foreach($orderData->products as $product){
 echo $product->order_product_id;
}

Please Log in or Create an account to join the conversation.

  • Posts: 64
  • Thank you received: 0
11 years 1 month ago #126696

Could you please give me an example of how to use hikashop_product_price_for_quantity_in_order function?When I use hikashop_product_price_for_quantity_in_cart it stores that price as order_product_price.If we use same calculation in hikashop_product_price_for_quantity_in_order it again calculates the price.Is there any way to save order_product_price when we use create order in backend not using cart?

I use this function as well but it does not save in order_product_price.

public function onBeforeCalculateProductPriceForQuantityInOrder(&$products){
$newPrice = $this->getNewPrice($products->order_product_id,$products->order_product_price);
$products->order_product_price = $newPrice;
}

Above function shows the currect price when we edit order but does not save in table.

Please let me know if not clear.

Thanks.

Please Log in or Create an account to join the conversation.

  • Posts: 13201
  • Thank you received: 2322
11 years 1 month ago #126755

Hi,

Here is the donation plugin, it use these functions so you can use it as example:
hikashop.com/en/component/updateme/ctrl-...plugin-donation.html

Please Log in or Create an account to join the conversation.

Time to create page: 0.104 seconds
Powered by Kunena Forum