316 lines
13 KiB
PHP
316 lines
13 KiB
PHP
<?php
|
|
|
|
namespace KupShop\ContentBundle\Tests;
|
|
|
|
use KupShop\DevelopmentBundle\Util\Tests\CartTestTrait;
|
|
|
|
class CartPriceDontCountinTest extends \DatabaseTestCase
|
|
{
|
|
use CartTestTrait;
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom */
|
|
public function testDeliveryTypeDontCountinFrom($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
$this->createCart();
|
|
$this->setDeliveryType($deliveryTypeId);
|
|
$this->setInvoice();
|
|
$this->insertProduct(3, null, $itemPieces);
|
|
$this->visitStep('delivery');
|
|
$this->cart->createFromDB();
|
|
|
|
$this->assertEquals($expectedCartPrice, $this->cart->totalPricePay->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is used (DeliveryType dont_countin_from = 500)
|
|
[1, 800, 1],
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// product 661.1570*1.21 + delivery 70.3*1.15 (15% vat) = 880.84497 (see getDataSet())
|
|
[2, 881, 1],
|
|
// Delivery dont_countin_from is used (Delivery dont_countin_from = 999)
|
|
[2, 1600, 2],
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_coupon500 */
|
|
public function testDeliveryTypeDontCountinFromCoupon500($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
$this->createCart();
|
|
$this->setDeliveryType($deliveryTypeId);
|
|
$this->setInvoice();
|
|
$this->insertProduct(3, null, $itemPieces); // product price = 800
|
|
$this->cart->addCoupon('500-0FJTR1IP'); // -500
|
|
$this->visitStep('delivery');
|
|
$this->cart->createFromDB();
|
|
|
|
$this->assertEquals($expectedCartPrice, $this->cart->totalPricePay->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_coupon500()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is not used (DeliveryType dont_countin_from = 500)
|
|
// max(product 661.1570*1.21 - 500, 0) + delivery 70.3*1.15 (15% vat) = 380.84497 (see getDataSet())
|
|
[1, 381, 1],
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 661.1570*1.21 - 500, 0) + delivery 70.3*1.15 (15% vat) = 380.84497 (see getDataSet())
|
|
[2, 381, 1],
|
|
// Delivery dont_countin_from is used (Delivery dont_countin_from = 999)
|
|
// max(product 2*661.1570*1.21 - 500, 0) + free delivery = 1099.99994 (see getDataSet())
|
|
[2, 1100, 2],
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_coupon1000 */
|
|
public function testDeliveryTypeDontCountinFromCoupon1000($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
$this->createCart();
|
|
$this->setDeliveryType($deliveryTypeId);
|
|
$this->setInvoice();
|
|
$this->insertProduct(3, null, $itemPieces); // product price = 800
|
|
$this->cart->addCoupon('1000-0FJTR1IP'); // -1000
|
|
$this->visitStep('delivery');
|
|
$this->cart->createFromDB();
|
|
|
|
$this->assertEquals($expectedCartPrice, $this->cart->totalPricePay->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_coupon1000()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is not used (DeliveryType dont_countin_from = 500)
|
|
// max(product 661.1570*1.21 - 1000, 0) + delivery 70.3*1.15 (15% vat) = 80.845 (see getDataSet())
|
|
[1, 81, 1], // 81 - delivery price
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 661.1570*1.21 - 1000, 0) + delivery 70.3*1.15 (15% vat) = 80.845 (see getDataSet())
|
|
[2, 81, 1], // 81 - delivery price
|
|
// Delivery dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 2*661.1570*1.21 - 1000, 0) + delivery 70.3*1.15 (15% vat) = 680.84494 (see getDataSet())
|
|
[2, 681, 2], // 2*800 (products) - 1000 (coupon) + 81 (delivery)
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_applyDiscountOnDelivery */
|
|
public function testDeliveryTypeDontCountinFromApplyDiscountOnDelivery($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
// apply_discount_on_delivery = Aplikuje slevu (kupon) i na dopravu
|
|
$this->addModule(\Modules::DELIVERY_TYPES, \Modules::SUB_APPLY_DISCOUNT_ON_DELIVERY);
|
|
|
|
$this->createCart();
|
|
$this->setDeliveryType($deliveryTypeId);
|
|
$this->setInvoice();
|
|
$this->insertProduct(3, null, $itemPieces); // product price = 800
|
|
$this->cart->addCoupon('1000-0FJTR1IP'); // -1000
|
|
$this->visitStep('delivery');
|
|
$this->cart->createFromDB();
|
|
|
|
$this->assertEquals($expectedCartPrice, $this->cart->totalPricePay->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_applyDiscountOnDelivery()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is not used (DeliveryType dont_countin_from = 500)
|
|
[1, 0, 1], // 800 (products) + 81 (delivery) - 1000 (coupon)
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
[2, 0, 1], // 800 (products) + 81 (delivery) - 1000 (coupon)
|
|
// Delivery dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 2*661.1570*1.21 + delivery 70.3*1.15 (15% vat) - 1000, 0) = 680.84494 (see getDataSet())
|
|
[2, 681, 2], // 2*800 (products) + 81 (delivery) - 1000 (coupon)
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_freeDeliveryNoDiscount */
|
|
public function testDeliveryTypeDontCountinFromFreeDeliveryNoDiscount($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
// free_delivery_no_discount = Počítá cenu pro dopravu zdarma před odečtením slev
|
|
$this->addModule(\Modules::DELIVERY_TYPES, \Modules::SUB_FREE_DELIVERY_NO_DISCOUNT);
|
|
|
|
$this->createCart();
|
|
$this->setDeliveryType($deliveryTypeId);
|
|
$this->setInvoice();
|
|
$this->insertProduct(3, null, $itemPieces); // product price = 800
|
|
$this->cart->addCoupon('500-0FJTR1IP'); // -500
|
|
$this->visitStep('delivery');
|
|
$this->cart->createFromDB();
|
|
|
|
$this->assertEquals($expectedCartPrice, $this->cart->totalPricePay->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_freeDeliveryNoDiscount()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is used (DeliveryType dont_countin_from = 500 (před odečtením slev))
|
|
[1, 300, 1],
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999)
|
|
// max(product 661.1570*1.21 - 500, 0) + delivery 70.3*1.15 (15% vat) = 380.84497 (see getDataSet())
|
|
[2, 381, 1],
|
|
// Delivery dont_countin_from is used (Delivery dont_countin_from = 999)
|
|
[2, 1100, 2],
|
|
];
|
|
}
|
|
|
|
/** @dataProvider data_DeliveryTypeDontCountinFrom_freeDeliveryNoDiscount_applyDiscountOnDelivery */
|
|
public function testDeliveryTypeDontCountinFromFreeDeliveryNoDiscountApplyDiscountOnDelivery($deliveryTypeId, $expectedCartPrice, $itemPieces)
|
|
{
|
|
// free_delivery_no_discount = Počítá cenu pro dopravu zdarma před odečtením slev
|
|
$this->addModule(\Modules::DELIVERY_TYPES, \Modules::SUB_FREE_DELIVERY_NO_DISCOUNT);
|
|
// apply_discount_on_delivery = Aplikuje slevu (kupon) i na dopravu
|
|
$this->addModule(\Modules::DELIVERY_TYPES, \Modules::SUB_APPLY_DISCOUNT_ON_DELIVERY);
|
|
|
|
$this->createCart();
|
|
$this->setDeliveryType($deliveryTypeId);
|
|
$this->setInvoice();
|
|
$this->insertProduct(3, null, $itemPieces); // product price = 800
|
|
$this->cart->addCoupon('1000-0FJTR1IP'); // -1000
|
|
$this->visitStep('delivery');
|
|
$this->cart->createFromDB();
|
|
|
|
$this->assertEquals($expectedCartPrice, $this->cart->totalPricePay->asFloat());
|
|
$this->checkOrderPriceIsSameAsCart();
|
|
}
|
|
|
|
public function data_DeliveryTypeDontCountinFrom_freeDeliveryNoDiscount_applyDiscountOnDelivery()
|
|
{
|
|
return [
|
|
// DeliveryType dont_countin_from is used (DeliveryType dont_countin_from = 500 (před odečtením slev))
|
|
[1, 0, 1], // 800 (products) + 0 (delivery) - 1000 (coupon)
|
|
// DeliveryType dont_countin_from is not used (Delivery dont_countin_from = 999 (před odečtením slev))
|
|
[2, 0, 1], // 800 (products) + 81 (delivery) - 1000 (coupon)
|
|
// Delivery dont_countin_from is used (Delivery dont_countin_from = 999 (před odečtením slev))
|
|
[2, 600, 2], // 2*800 (products) + 0 (delivery) - 1000 (coupon)
|
|
];
|
|
}
|
|
|
|
protected function getDataSet()
|
|
{
|
|
return $this->getJsonDataSet(/* @lang JSON */ '
|
|
{
|
|
"delivery_type_delivery": [
|
|
{
|
|
"id":1,
|
|
"currency":"CZK",
|
|
"name":"Česká pošta",
|
|
"price":"70.3",
|
|
"photo":null,
|
|
"class":"BalikDoRuky",
|
|
"time_days":null,
|
|
"time_hours":null,
|
|
"description":null,
|
|
"currencies":null,
|
|
"id_pricelist":null,
|
|
"price_dont_countin_from":"999"
|
|
}
|
|
],
|
|
"delivery_type_payment": [
|
|
{
|
|
"id":1,
|
|
"currency":"CZK",
|
|
"name":"dobírka",
|
|
"price":"0",
|
|
"class":null,
|
|
"photo":null,
|
|
"description":null
|
|
},
|
|
{
|
|
"id":2,
|
|
"currency":"CZK",
|
|
"name":"online",
|
|
"price":"0",
|
|
"class":null,
|
|
"photo":null,
|
|
"description":null
|
|
}
|
|
],
|
|
"delivery_type": [
|
|
{
|
|
"id":1,
|
|
"currency":"CZK",
|
|
"id_delivery":1,
|
|
"id_payment":1,
|
|
"price":null,
|
|
"vat":2,
|
|
"price_dont_countin_from":"500",
|
|
"format":null,
|
|
"figure":"Y",
|
|
"description":null,
|
|
"payment_class":null
|
|
},
|
|
{
|
|
"id":2,
|
|
"currency":"CZK",
|
|
"id_delivery":1,
|
|
"id_payment":2,
|
|
"price":null,
|
|
"vat":2,
|
|
"price_dont_countin_from":null,
|
|
"format":null,
|
|
"figure":"Y",
|
|
"description":null,
|
|
"payment_class":null
|
|
}
|
|
],
|
|
"order_discounts": [
|
|
{
|
|
"id": 1,
|
|
"date_created": "2024-02-29 10:16:54",
|
|
"name": "slevový kupón 500-0FJTR1IP",
|
|
"display_name": "Sleva 500 korun",
|
|
"uses_count": 0,
|
|
"active": "Y",
|
|
"data": null,
|
|
"position": 1,
|
|
"type": null
|
|
},
|
|
{
|
|
"id": 2,
|
|
"date_created": "2024-02-29 10:16:54",
|
|
"name": "slevový kupón 1000-0FJTR1IP",
|
|
"display_name": "Sleva 1000 korun",
|
|
"uses_count": 0,
|
|
"active": "Y",
|
|
"data": null,
|
|
"position": 2,
|
|
"type": null
|
|
}
|
|
],
|
|
"order_discounts_triggers": [
|
|
{
|
|
"id": 1,
|
|
"id_order_discount": 1,
|
|
"type": "coupon",
|
|
"data": "{\"codes\":[\"500-0FJTR1IP\"]}"
|
|
},
|
|
{
|
|
"id": 2,
|
|
"id_order_discount": 2,
|
|
"type": "coupon",
|
|
"data": "{\"codes\":[\"1000-0FJTR1IP\"],\"multiple\":\"N\"}"
|
|
}
|
|
],
|
|
"order_discounts_actions": [
|
|
{
|
|
"id": 1,
|
|
"id_order_discount": 1,
|
|
"type": "global_discount",
|
|
"data": "{\"discount\":\"500\",\"unit\":\"CZK\",\"vat\":\"1\",\"divideDiscountPrice\":\"N\"}"
|
|
},
|
|
{
|
|
"id": 2,
|
|
"id_order_discount": 2,
|
|
"type": "global_discount",
|
|
"data": "{\"discount\":\"1000\",\"unit\":\"CZK\",\"vat\":\"1\",\"divideDiscountPrice\":\"N\"}"
|
|
}
|
|
]
|
|
}
|
|
');
|
|
}
|
|
}
|