Set price and cost to zero

How to configure and adapt Aimeos based shops as developer
Forum rules
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
adityabanerjee
Posts: 44
Joined: 05 Oct 2019, 06:42

Set price and cost to zero

Post by adityabanerjee » 01 Aug 2022, 11:16

Hi Aimeos,

I want to set price and delivery cost to 0 when the status of the order is set to Cancelled. This is what I have right now.

Code: Select all

<?php

/**
 * @license LGPLv3, https://opensource.org/licenses/LGPL-3.0
 * @copyright Metaways Infosystems GmbH, 2011
 * @copyright Aimeos (aimeos.org), 2015-2021
 * @package MShop
 * @subpackage Order
 */


namespace Aimeos\MShop\Order\Item\Base;


/**
 * Default implementation of the shopping basket.
 *
 * @package MShop
 * @subpackage Order
 */
class EbdaaOrderItemBase extends Standard
{
    /**
	 * Returns a price item with amounts calculated for the products, costs, etc.
	 *
	 * @return \Aimeos\MShop\Price\Item\Iface Price item with price, costs and rebate the customer has to pay
	 */
	public function getPrice() : \Aimeos\MShop\Price\Item\Iface
	{
		if( $this->recalc )
        {
            $price = $this->price->clear();

            foreach( $this->getServices() as $list )
            {
                foreach( $list as $service ) {
                    $price = $price->addItem( $service->getPrice() );
                }
            }

            foreach( $this->getProducts() as $product ) { 
                // 0=deleted, 1=cancelled //removed 1 and rolled back
                //as it was causing order.base.price to go 0 when 
                // we were choosing package ready
                if( !in_array( $product->getStatus(), [0] ) ) {
                    $price = $price->addItem( $product->getPrice(),
                    $product->getQuantity() );
                }
            }

            $this->price = $price;
            $this->recalc = false;
        }

	    return $this->price;
	}
    
}
Now If I change the status to cancelled I want the "order.base.price" and "order.base.costs" to be set to zero. Please assist.

adityabanerjee
Posts: 44
Joined: 05 Oct 2019, 06:42

Re: Set price and cost to zero

Post by adityabanerjee » 02 Aug 2022, 07:16

Please assist here.

User avatar
aimeos
Administrator
Posts: 7866
Joined: 01 Jan 1970, 00:00

Re: Set price and cost to zero

Post by aimeos » 02 Aug 2022, 16:13

Why do you want to set the price to zero? This makes usually no sense because the "cancelled" status removes the order price from being used and if the status is reverted back, you will have no price any more. That said, setting the price to zero is not recommended at all.

Back to your question:
In the order base item, there's no way to set the price based on the order payment status because this the status is only available in the order item (not order base item). Thus, you can only set the price in the order manager when the status change is saved.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, Image give us a star

Post Reply