Shipping and handling cost dependent of the amount of items
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!
Always add your Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Shipping and handling cost dependent of the amount of items
Hi
I configure at the moment the shipping cost and need some help.
I would like to calculate the shipping cost dependent of the amount of items at the basket.
For example:
1 item = 1.45 Euro
2 items = 2.60 Euro
3 items = 3.20 Euro
4 items and more 4.50 Euro
Maybe there is something in the documentation but I'm to dumb to find it
Or need I to write a Decorator for this behavior?
I configure at the moment the shipping cost and need some help.
I would like to calculate the shipping cost dependent of the amount of items at the basket.
For example:
1 item = 1.45 Euro
2 items = 2.60 Euro
3 items = 3.20 Euro
4 items and more 4.50 Euro
Maybe there is something in the documentation but I'm to dumb to find it
Or need I to write a Decorator for this behavior?
Re: Shipping and handling cost dependent of the amount of it
For linear shipping costs, you could have used "costs per item" for each product but you have a cut after four items so you need to create your own decorator. You can use the "MShop_Service_Provider_Decorator_Costs" as reference.Mirco wrote: I would like to calculate the shipping cost dependent of the amount of items at the basket.
For example:
1 item = 1.45 Euro
2 items = 2.60 Euro
3 items = 3.20 Euro
4 items and more 4.50 Euro
Maybe there is something in the documentation but I'm to dumb to find it
Or need I to write a Decorator for this behavior?
Re: Shipping and handling cost dependent of the amount of it
Thanks!
I have done my one Decorator "Delivery.php". The base was the Costs.php Decorator as suggested.
I changed the function calcPrice( MShop_Order_Item_Base_Interface $basket )
I'm note quite sure if this the right way but it works.
I have done my one Decorator "Delivery.php". The base was the Costs.php Decorator as suggested.
I changed the function calcPrice( MShop_Order_Item_Base_Interface $basket )
I'm note quite sure if this the right way but it works.
Code: Select all
public function calcPrice( MShop_Order_Item_Base_Interface $basket )
{
$config = $this->getServiceItem()->getConfig();
if( !isset( $config['delivery.amount'] ) ) {
throw new MShop_Service_Provider_Exception( sprintf( 'Missing configuration "%1$s"', 'delivery.amount' ) );
}
$count = 0;
foreach( $basket->getProducts() as $product )
{
$count += $product->getQuantity();
}
$price = $this->_getProvider()->calcPrice( $basket );
if ($count == 1) {
$price->setValue( 0.0);
$price->setCosts( 1.45);
} else if ($count == 2) {
$price->setValue( 0.0);
$price->setCosts(2.40);
} else if ($count == 3) {
$price->setValue( 0.0);
$price->setCosts(5.0);
} else if ($count > 3) {
$price->setValue( 0.0);
$price->setCosts( 6.8);
}
return $price;
}
Re: Shipping and handling cost dependent of the amount of it
Looks goodMirco wrote:I'm note quite sure if this the right way but it works.
Code: Select all
$config = $this->getServiceItem()->getConfig();
if( !isset( $config['delivery.amount'] ) ) {
throw new MShop_Service_Provider_Exception( sprintf( 'Missing configuration "%1$s"', 'delivery.amount' ) );
}
Code: Select all
$price->setValue( 0.0);
$price->setCosts( 1.45);
Code: Select all
$price->setCosts( $price->getCosts() + $amount );