|
|
|
|
@ -13,6 +13,7 @@ use Webkul\CartRule\Models\CartRuleCoupon;
|
|
|
|
|
use Webkul\Core\Helpers\Laravel5Helper;
|
|
|
|
|
use Webkul\Customer\Models\Customer;
|
|
|
|
|
use Webkul\Customer\Models\CustomerAddress;
|
|
|
|
|
use Illuminate\Contracts\Support\Arrayable;
|
|
|
|
|
use Webkul\Product\Repositories\ProductDownloadableLinkRepository;
|
|
|
|
|
use Webkul\Sales\Repositories\DownloadableLinkPurchasedRepository;
|
|
|
|
|
use Webkul\Sales\Repositories\OrderItemRepository;
|
|
|
|
|
@ -24,219 +25,329 @@ use Cart;
|
|
|
|
|
|
|
|
|
|
class cartRuleWithCoupon
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public $cartRule;
|
|
|
|
|
|
|
|
|
|
public $coupon;
|
|
|
|
|
|
|
|
|
|
public function __construct(CartRule $cartRule, CartRuleCoupon $coupon)
|
|
|
|
|
{
|
|
|
|
|
$this->cartRule = $cartRule;
|
|
|
|
|
$this->coupon = $coupon;
|
|
|
|
|
$this->coupon = $coupon;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class expectedCartItem
|
|
|
|
|
class expectedCartItem implements Arrayable
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public const ITEM_DISCOUNT_AMOUNT_PRECISION = 4;
|
|
|
|
|
|
|
|
|
|
public const ITEM_TAX_AMOUNT_PRECISION = 4;
|
|
|
|
|
|
|
|
|
|
public $cart_id;
|
|
|
|
|
|
|
|
|
|
public $product_id;
|
|
|
|
|
|
|
|
|
|
public $quantity = 1;
|
|
|
|
|
|
|
|
|
|
public $price = 0.0;
|
|
|
|
|
|
|
|
|
|
public $base_price = 0.0;
|
|
|
|
|
|
|
|
|
|
public $total = 0.0;
|
|
|
|
|
|
|
|
|
|
public $base_total = 0.0;
|
|
|
|
|
|
|
|
|
|
public $tax_percent = 0.0;
|
|
|
|
|
|
|
|
|
|
public $tax_amount = 0.0;
|
|
|
|
|
|
|
|
|
|
public $base_tax_amount = 0.0;
|
|
|
|
|
|
|
|
|
|
public $coupon_code = null;
|
|
|
|
|
|
|
|
|
|
public $discount_percent = 0.0;
|
|
|
|
|
|
|
|
|
|
public $discount_amount = 0.0;
|
|
|
|
|
|
|
|
|
|
public $base_discount_amount = 0.0;
|
|
|
|
|
|
|
|
|
|
public $applied_cart_rule_ids = '';
|
|
|
|
|
|
|
|
|
|
public function __construct(int $cartId, int $productId)
|
|
|
|
|
{
|
|
|
|
|
$this->cart_id = $cartId;
|
|
|
|
|
$this->cart_id = $cartId;
|
|
|
|
|
$this->product_id = $productId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function calcTotals(): void
|
|
|
|
|
{
|
|
|
|
|
$this->total = $this->quantity * $this->price;
|
|
|
|
|
$this->total = $this->quantity * $this->price;
|
|
|
|
|
$this->base_total = $this->quantity * $this->price;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function calcTaxAmounts(): void
|
|
|
|
|
{
|
|
|
|
|
$this->tax_amount = round(
|
|
|
|
|
$this->quantity * $this->price * $this->tax_percent / 100,
|
|
|
|
|
self::ITEM_TAX_AMOUNT_PRECISION
|
|
|
|
|
);
|
|
|
|
|
$this->base_tax_amount = round(
|
|
|
|
|
$this->quantity * $this->price * $this->tax_percent / 100,
|
|
|
|
|
self::ITEM_TAX_AMOUNT_PRECISION
|
|
|
|
|
);
|
|
|
|
|
$this->tax_amount = round($this->quantity * $this->price * $this->tax_percent / 100, self::ITEM_TAX_AMOUNT_PRECISION);
|
|
|
|
|
$this->base_tax_amount = round($this->quantity * $this->price * $this->tax_percent / 100, self::ITEM_TAX_AMOUNT_PRECISION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function calcFixedDiscountAmounts(float $discount, float $baseDiscount, string $code, int $cartRuleId): void
|
|
|
|
|
{
|
|
|
|
|
$this->discount_amount = $this->quantity * $discount;
|
|
|
|
|
$this->base_discount_amount = $this->quantity * $baseDiscount;
|
|
|
|
|
$this->coupon_code = $code;
|
|
|
|
|
$this->applied_cart_rule_ids = (string)$cartRuleId;
|
|
|
|
|
$this->discount_amount = $this->quantity * $discount;
|
|
|
|
|
$this->base_discount_amount = $this->quantity * $baseDiscount;
|
|
|
|
|
$this->coupon_code = $code;
|
|
|
|
|
$this->applied_cart_rule_ids = (string) $cartRuleId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function calcPercentageDiscountAmounts(float $discount, string $code, int $cartRuleId): void
|
|
|
|
|
{
|
|
|
|
|
$this->discount_percent = $discount;
|
|
|
|
|
$this->discount_amount = round(
|
|
|
|
|
($this->total + $this->tax_amount) * $this->discount_percent / 100,
|
|
|
|
|
self::ITEM_DISCOUNT_AMOUNT_PRECISION
|
|
|
|
|
);
|
|
|
|
|
$this->base_discount_amount = round(
|
|
|
|
|
($this->base_total + $this->base_tax_amount) * $this->discount_percent / 100,
|
|
|
|
|
self::ITEM_DISCOUNT_AMOUNT_PRECISION
|
|
|
|
|
);
|
|
|
|
|
$this->coupon_code = $code;
|
|
|
|
|
$this->applied_cart_rule_ids = (string)$cartRuleId;
|
|
|
|
|
$this->discount_percent = $discount;
|
|
|
|
|
$this->discount_amount = round(($this->total + $this->tax_amount) * $this->discount_percent / 100, self::ITEM_DISCOUNT_AMOUNT_PRECISION);
|
|
|
|
|
$this->base_discount_amount = round(($this->base_total + $this->base_tax_amount) * $this->discount_percent / 100, self::ITEM_DISCOUNT_AMOUNT_PRECISION);
|
|
|
|
|
$this->coupon_code = $code;
|
|
|
|
|
$this->applied_cart_rule_ids = (string) $cartRuleId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toArray(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'cart_id' => $this->cart_id,
|
|
|
|
|
'product_id' => $this->product_id,
|
|
|
|
|
'quantity' => $this->quantity,
|
|
|
|
|
'price' => $this->price,
|
|
|
|
|
'base_price' => $this->base_price,
|
|
|
|
|
'total' => $this->total,
|
|
|
|
|
'base_total' => $this->base_total,
|
|
|
|
|
'tax_percent' => $this->tax_percent,
|
|
|
|
|
'tax_amount' => $this->tax_amount,
|
|
|
|
|
'base_tax_amount' => $this->base_tax_amount,
|
|
|
|
|
'coupon_code' => $this->coupon_code,
|
|
|
|
|
'discount_percent' => $this->discount_percent,
|
|
|
|
|
'discount_amount' => $this->discount_amount,
|
|
|
|
|
'base_discount_amount' => $this->base_discount_amount,
|
|
|
|
|
'applied_cart_rule_ids' => $this->applied_cart_rule_ids,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class expectedCart
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public const CART_TOTAL_PRECISION = 2;
|
|
|
|
|
|
|
|
|
|
public $customer_id;
|
|
|
|
|
|
|
|
|
|
public $id;
|
|
|
|
|
|
|
|
|
|
public $items_count = 0;
|
|
|
|
|
|
|
|
|
|
public $items_qty = 0.0;
|
|
|
|
|
|
|
|
|
|
public $sub_total = 0.0;
|
|
|
|
|
|
|
|
|
|
public $tax_total = 0.0;
|
|
|
|
|
|
|
|
|
|
public $discount_amount = 0.0;
|
|
|
|
|
|
|
|
|
|
public $grand_total = 0.0;
|
|
|
|
|
|
|
|
|
|
public $base_sub_total = 0.0;
|
|
|
|
|
|
|
|
|
|
public $base_tax_total = 0.0;
|
|
|
|
|
|
|
|
|
|
public $base_discount_amount = 0.0;
|
|
|
|
|
|
|
|
|
|
public $base_grand_total = 0.0;
|
|
|
|
|
|
|
|
|
|
public $coupon_code = null;
|
|
|
|
|
|
|
|
|
|
public $applied_cart_rule_ids = '';
|
|
|
|
|
|
|
|
|
|
public function __construct(int $cartId, int $customerId)
|
|
|
|
|
{
|
|
|
|
|
$this->id = $cartId;
|
|
|
|
|
$this->id = $cartId;
|
|
|
|
|
$this->customer_id = $customerId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function applyCoupon(int $cartRuleId, string $couponCode): void
|
|
|
|
|
{
|
|
|
|
|
$this->coupon_code = $couponCode;
|
|
|
|
|
$this->applied_cart_rule_ids = (string)$cartRuleId;
|
|
|
|
|
$this->coupon_code = $couponCode;
|
|
|
|
|
$this->applied_cart_rule_ids = (string) $cartRuleId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function finalizeTotals(): void
|
|
|
|
|
{
|
|
|
|
|
$this->sub_total = round($this->sub_total, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->tax_total = round($this->tax_total, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->sub_total = round($this->sub_total, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->tax_total = round($this->tax_total, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->discount_amount = round($this->discount_amount, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->grand_total = round($this->sub_total + $this->tax_total - $this->discount_amount,
|
|
|
|
|
self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->grand_total = round($this->sub_total + $this->tax_total - $this->discount_amount, self::CART_TOTAL_PRECISION);
|
|
|
|
|
|
|
|
|
|
$this->base_sub_total = round($this->base_sub_total, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->base_tax_total = round($this->base_tax_total, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->base_sub_total = round($this->base_sub_total, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->base_tax_total = round($this->base_tax_total, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->base_discount_amount = round($this->base_discount_amount, self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->base_grand_total = round($this->base_sub_total + $this->base_tax_total - $this->base_discount_amount,
|
|
|
|
|
self::CART_TOTAL_PRECISION);
|
|
|
|
|
$this->base_grand_total = round($this->base_sub_total + $this->base_tax_total - $this->base_discount_amount, self::CART_TOTAL_PRECISION);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toArray(): array
|
|
|
|
|
{
|
|
|
|
|
return (array)$this;
|
|
|
|
|
return (array) $this;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class expectedOrder
|
|
|
|
|
class expectedOrder implements Arrayable
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
public $status;
|
|
|
|
|
|
|
|
|
|
public $customer_email;
|
|
|
|
|
|
|
|
|
|
public $customer_first_name;
|
|
|
|
|
|
|
|
|
|
public $customer_vat_id;
|
|
|
|
|
|
|
|
|
|
public $coupon_code;
|
|
|
|
|
|
|
|
|
|
public $total_item_count;
|
|
|
|
|
|
|
|
|
|
public $total_qty_ordered;
|
|
|
|
|
|
|
|
|
|
public $grand_total;
|
|
|
|
|
|
|
|
|
|
public $base_grand_total;
|
|
|
|
|
|
|
|
|
|
public $sub_total;
|
|
|
|
|
|
|
|
|
|
public $base_sub_total;
|
|
|
|
|
|
|
|
|
|
public $discount_amount;
|
|
|
|
|
|
|
|
|
|
public $base_discount_amount;
|
|
|
|
|
|
|
|
|
|
public $tax_amount;
|
|
|
|
|
|
|
|
|
|
public $base_tax_amount;
|
|
|
|
|
|
|
|
|
|
public $customer_id;
|
|
|
|
|
|
|
|
|
|
public $cart_id;
|
|
|
|
|
|
|
|
|
|
public $applied_cart_rule_ids;
|
|
|
|
|
|
|
|
|
|
public $shipping_method;
|
|
|
|
|
|
|
|
|
|
public $shipping_amount;
|
|
|
|
|
|
|
|
|
|
public $base_shipping_amount;
|
|
|
|
|
|
|
|
|
|
public $shipping_discount_amount;
|
|
|
|
|
|
|
|
|
|
public function __construct(expectedCart $expectedCart, Customer $customer, int $cartId)
|
|
|
|
|
{
|
|
|
|
|
$this->status = 'pending';
|
|
|
|
|
$this->customer_email = $customer->email;
|
|
|
|
|
$this->customer_first_name = $customer->first_name;
|
|
|
|
|
$this->customer_vat_id = $customer->vat_id;
|
|
|
|
|
$this->coupon_code = $expectedCart->coupon_code;
|
|
|
|
|
$this->total_item_count = $expectedCart->items_count;
|
|
|
|
|
$this->total_qty_ordered = $expectedCart->items_qty;
|
|
|
|
|
$this->grand_total = $expectedCart->grand_total;
|
|
|
|
|
$this->base_grand_total = $expectedCart->base_grand_total;
|
|
|
|
|
$this->sub_total = $expectedCart->sub_total;
|
|
|
|
|
$this->base_sub_total = $expectedCart->base_sub_total;
|
|
|
|
|
$this->discount_amount = $expectedCart->discount_amount;
|
|
|
|
|
$this->base_discount_amount = $expectedCart->base_discount_amount;
|
|
|
|
|
$this->tax_amount = $expectedCart->tax_total;
|
|
|
|
|
$this->base_tax_amount = $expectedCart->base_tax_total;
|
|
|
|
|
$this->customer_id = $customer->id;
|
|
|
|
|
$this->cart_id = $cartId;
|
|
|
|
|
$this->applied_cart_rule_ids = $expectedCart->applied_cart_rule_ids;
|
|
|
|
|
$this->shipping_method = null;
|
|
|
|
|
$this->shipping_amount = null;
|
|
|
|
|
$this->base_shipping_amount = null;
|
|
|
|
|
$this->status = 'pending';
|
|
|
|
|
$this->customer_email = $customer->email;
|
|
|
|
|
$this->customer_first_name = $customer->first_name;
|
|
|
|
|
$this->customer_vat_id = $customer->vat_id;
|
|
|
|
|
$this->coupon_code = $expectedCart->coupon_code;
|
|
|
|
|
$this->total_item_count = $expectedCart->items_count;
|
|
|
|
|
$this->total_qty_ordered = $expectedCart->items_qty;
|
|
|
|
|
$this->grand_total = $expectedCart->grand_total;
|
|
|
|
|
$this->base_grand_total = $expectedCart->base_grand_total;
|
|
|
|
|
$this->sub_total = $expectedCart->sub_total;
|
|
|
|
|
$this->base_sub_total = $expectedCart->base_sub_total;
|
|
|
|
|
$this->discount_amount = $expectedCart->discount_amount;
|
|
|
|
|
$this->base_discount_amount = $expectedCart->base_discount_amount;
|
|
|
|
|
$this->tax_amount = $expectedCart->tax_total;
|
|
|
|
|
$this->base_tax_amount = $expectedCart->base_tax_total;
|
|
|
|
|
$this->customer_id = $customer->id;
|
|
|
|
|
$this->cart_id = $cartId;
|
|
|
|
|
$this->applied_cart_rule_ids = $expectedCart->applied_cart_rule_ids;
|
|
|
|
|
$this->shipping_method = null;
|
|
|
|
|
$this->shipping_amount = null;
|
|
|
|
|
$this->base_shipping_amount = null;
|
|
|
|
|
$this->shipping_discount_amount = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function toArray(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
'status' => $this->status,
|
|
|
|
|
'customer_email' => $this->customer_email,
|
|
|
|
|
'customer_first_name' => $this->customer_first_name,
|
|
|
|
|
'customer_vat_id' => $this->customer_vat_id,
|
|
|
|
|
'coupon_code' => $this->coupon_code,
|
|
|
|
|
'total_item_count' => $this->total_item_count,
|
|
|
|
|
'total_qty_ordered' => $this->total_qty_ordered,
|
|
|
|
|
'grand_total' => $this->grand_total,
|
|
|
|
|
'base_grand_total' => $this->base_grand_total,
|
|
|
|
|
'sub_total' => $this->sub_total,
|
|
|
|
|
'base_sub_total' => $this->base_sub_total,
|
|
|
|
|
'discount_amount' => $this->discount_amount,
|
|
|
|
|
'base_discount_amount' => $this->base_discount_amount,
|
|
|
|
|
'tax_amount' => $this->tax_amount,
|
|
|
|
|
'base_tax_amount' => $this->base_tax_amount,
|
|
|
|
|
'customer_id' => $this->customer_id,
|
|
|
|
|
'cart_id' => $this->cart_id,
|
|
|
|
|
'applied_cart_rule_ids' => $this->applied_cart_rule_ids,
|
|
|
|
|
'shipping_method' => $this->shipping_method,
|
|
|
|
|
'shipping_amount' => $this->shipping_amount,
|
|
|
|
|
'base_shipping_amount' => $this->base_shipping_amount,
|
|
|
|
|
'shipping_discount_amount' => $this->shipping_discount_amount,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class CartRuleCest
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
private $products;
|
|
|
|
|
|
|
|
|
|
private $sessionToken;
|
|
|
|
|
|
|
|
|
|
public const PRODUCT_PRICE = 13.57;
|
|
|
|
|
|
|
|
|
|
public const REDUCED_PRODUCT_PRICE = 7.21;
|
|
|
|
|
|
|
|
|
|
public const TAX_RATE = 18.5;
|
|
|
|
|
|
|
|
|
|
public const REDUCED_TAX_RATE = 5.5;
|
|
|
|
|
|
|
|
|
|
public const DISCOUNT_AMOUNT_FIX = 3.37;
|
|
|
|
|
|
|
|
|
|
public const DISCOUNT_AMOUNT_PERCENT = 7.5;
|
|
|
|
|
|
|
|
|
|
public const DISCOUNT_AMOUNT_FIX_FULL = 999999.99;
|
|
|
|
|
|
|
|
|
|
public const DISCOUNT_AMOUNT_CART = 8.33;
|
|
|
|
|
|
|
|
|
|
public const ACTION_TYPE_FIXED = "by_fixed";
|
|
|
|
|
|
|
|
|
|
public const ACTION_TYPE_PERCENTAGE = "by_percent";
|
|
|
|
|
|
|
|
|
|
public const ACTION_TYPE_CART_FIXED = "cart_fixed";
|
|
|
|
|
|
|
|
|
|
public const PRODUCT_FREE = 0;
|
|
|
|
|
|
|
|
|
|
public const PRODUCT_NOT_FREE = 1;
|
|
|
|
|
|
|
|
|
|
public const PRODUCT_NOT_FREE_REDUCED_TAX = 2;
|
|
|
|
|
|
|
|
|
|
public const TAX_CATEGORY = 0;
|
|
|
|
|
|
|
|
|
|
public const TAX_REDUCED_CATEGORY = 1;
|
|
|
|
|
|
|
|
|
|
public const COUPON_FIXED = 0;
|
|
|
|
|
|
|
|
|
|
public const COUPON_FIXED_FULL = 1;
|
|
|
|
|
|
|
|
|
|
public const COUPON_PERCENTAGE = 2;
|
|
|
|
|
|
|
|
|
|
public const COUPON_PERCENTAGE_FULL = 3;
|
|
|
|
|
|
|
|
|
|
public const COUPON_FIXED_CART = 4;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -471,8 +582,8 @@ class CartRuleCest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \UnitTester $I
|
|
|
|
|
* @param \Codeception\Example $scenario
|
|
|
|
|
* @param \UnitTester $I
|
|
|
|
|
* @param \Codeception\Example $scenario
|
|
|
|
|
*
|
|
|
|
|
* @dataProvider getCartWithCouponScenarios
|
|
|
|
|
* @group slow_unit
|
|
|
|
|
@ -485,13 +596,15 @@ class CartRuleCest
|
|
|
|
|
config(['app.default_country' => 'DE']);
|
|
|
|
|
|
|
|
|
|
$customer = $I->have(Customer::class);
|
|
|
|
|
auth()->guard('customer')->loginUsingId($customer->id);
|
|
|
|
|
auth()
|
|
|
|
|
->guard('customer')
|
|
|
|
|
->loginUsingId($customer->id);
|
|
|
|
|
Event::dispatch('customer.after.login', $customer['email']);
|
|
|
|
|
|
|
|
|
|
$this->sessionToken = $faker->uuid;
|
|
|
|
|
session(['_token' => $this->sessionToken]);
|
|
|
|
|
|
|
|
|
|
$taxCategories = $this->generateTaxCategories($I);
|
|
|
|
|
$taxCategories = $this->generateTaxCategories($I);
|
|
|
|
|
$this->products = $this->generateProducts($I, $scenario['productSequence'], $taxCategories);
|
|
|
|
|
|
|
|
|
|
$cartRuleWithCoupon = null;
|
|
|
|
|
@ -511,8 +624,10 @@ class CartRuleCest
|
|
|
|
|
|
|
|
|
|
if ($scenario['withCoupon']) {
|
|
|
|
|
$expectedCartCoupon = $cartRuleWithCoupon->coupon->code;
|
|
|
|
|
$I->comment('I try to use coupon code ' . $expectedCartCoupon);
|
|
|
|
|
cart()->setCouponCode($expectedCartCoupon)->collectTotals();
|
|
|
|
|
$I->comment('I try to use coupon code '.$expectedCartCoupon);
|
|
|
|
|
cart()
|
|
|
|
|
->setCouponCode($expectedCartCoupon)
|
|
|
|
|
->collectTotals();
|
|
|
|
|
} else {
|
|
|
|
|
$I->comment('I have no coupon');
|
|
|
|
|
$expectedCartCoupon = null;
|
|
|
|
|
@ -525,7 +640,11 @@ class CartRuleCest
|
|
|
|
|
$expectedCartItems = $this->checkMaxDiscount($expectedCartItems);
|
|
|
|
|
|
|
|
|
|
foreach ($expectedCartItems as $expectedCartItem) {
|
|
|
|
|
$I->seeRecord('cart_items', $expectedCartItem);
|
|
|
|
|
/**
|
|
|
|
|
* @var $expectedCartItem \Tests\Unit\CartRule\expectedCartItem
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
$I->seeRecord('cart_items', $expectedCartItem->toArray());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$expectedCart = $this->getExpectedCart($cart->id, $expectedCartItems, $cartRuleWithCoupon);
|
|
|
|
|
@ -569,17 +688,18 @@ class CartRuleCest
|
|
|
|
|
cart()->saveShippingMethod('free_free');
|
|
|
|
|
cart()->savePaymentMethod(['method' => 'mollie_creditcard']);
|
|
|
|
|
$I->assertFalse(cart()->hasError());
|
|
|
|
|
$orderItemRepository = new OrderItemRepository(app());
|
|
|
|
|
$downloadableLinkRepository = new ProductDownloadableLinkRepository(app());
|
|
|
|
|
$downloadableLinkPurchasedRepository =
|
|
|
|
|
new DownloadableLinkPurchasedRepository($downloadableLinkRepository, app());
|
|
|
|
|
$orderRepository = new OrderRepository($orderItemRepository, $downloadableLinkPurchasedRepository, app());
|
|
|
|
|
$orderItemRepository = new OrderItemRepository(app());
|
|
|
|
|
$downloadableLinkRepository = new ProductDownloadableLinkRepository(app());
|
|
|
|
|
$downloadableLinkPurchasedRepository = new DownloadableLinkPurchasedRepository($downloadableLinkRepository, app());
|
|
|
|
|
$orderRepository = new OrderRepository($orderItemRepository, $downloadableLinkPurchasedRepository, app());
|
|
|
|
|
|
|
|
|
|
$orderRepository->create(cart()->prepareDataForOrder());
|
|
|
|
|
$expectedOrder = new expectedOrder($expectedCart, $customer, $cart->id);
|
|
|
|
|
$I->seeRecord('orders', $expectedOrder);
|
|
|
|
|
$I->seeRecord('orders', $expectedOrder->toArray());
|
|
|
|
|
|
|
|
|
|
auth()->guard('customer')->logout();
|
|
|
|
|
auth()
|
|
|
|
|
->guard('customer')
|
|
|
|
|
->logout();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -591,7 +711,9 @@ class CartRuleCest
|
|
|
|
|
|
|
|
|
|
$customer = $I->have(Customer::class);
|
|
|
|
|
|
|
|
|
|
auth()->guard('customer')->loginUsingId($customer->id);
|
|
|
|
|
auth()
|
|
|
|
|
->guard('customer')
|
|
|
|
|
->loginUsingId($customer->id);
|
|
|
|
|
Event::dispatch('customer.after.login', $customer['email']);
|
|
|
|
|
|
|
|
|
|
$this->sessionToken = $faker->uuid;
|
|
|
|
|
@ -615,7 +737,7 @@ class CartRuleCest
|
|
|
|
|
'tax_category_id' => $taxCategorie->id,
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$product = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $productConfig);
|
|
|
|
|
$product = $I->haveProduct(Laravel5Helper::SIMPLE_PRODUCT, $productConfig);
|
|
|
|
|
|
|
|
|
|
$ruleConfig = [
|
|
|
|
|
'action_type' => self::ACTION_TYPE_PERCENTAGE,
|
|
|
|
|
@ -629,24 +751,27 @@ class CartRuleCest
|
|
|
|
|
],
|
|
|
|
|
],
|
|
|
|
|
];
|
|
|
|
|
$cartRule = $I->have(CartRule::class, $ruleConfig);
|
|
|
|
|
$cartRule = $I->have(CartRule::class, $ruleConfig);
|
|
|
|
|
|
|
|
|
|
DB::table('cart_rule_channels')->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'channel_id' => core()->getCurrentChannel()->id,
|
|
|
|
|
]);
|
|
|
|
|
DB::table('cart_rule_channels')
|
|
|
|
|
->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'channel_id' => core()->getCurrentChannel()->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$guestCustomerGroup = $I->grabRecord('customer_groups', ['code' => 'guest']);
|
|
|
|
|
DB::table('cart_rule_customer_groups')->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'customer_group_id' => $guestCustomerGroup['id'],
|
|
|
|
|
]);
|
|
|
|
|
DB::table('cart_rule_customer_groups')
|
|
|
|
|
->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'customer_group_id' => $guestCustomerGroup['id'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$generalCustomerGroup = $I->grabRecord('customer_groups', ['code' => 'general']);
|
|
|
|
|
DB::table('cart_rule_customer_groups')->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'customer_group_id' => $generalCustomerGroup['id'],
|
|
|
|
|
]);
|
|
|
|
|
DB::table('cart_rule_customer_groups')
|
|
|
|
|
->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'customer_group_id' => $generalCustomerGroup['id'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$coupon = $I->have(CartRuleCoupon::class, [
|
|
|
|
|
'code' => 'AWESOME',
|
|
|
|
|
@ -655,15 +780,18 @@ class CartRuleCest
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$data = [
|
|
|
|
|
'_token' => session('_token'),
|
|
|
|
|
'product_id' => $product->id,
|
|
|
|
|
'quantity' => 1,
|
|
|
|
|
'_token' => session('_token'),
|
|
|
|
|
'product_id' => $product->id,
|
|
|
|
|
'quantity' => 1,
|
|
|
|
|
];
|
|
|
|
|
cart()->addProduct($product->id, $data);
|
|
|
|
|
cart()->setCouponCode('AWESOME')->collectTotals();
|
|
|
|
|
cart()
|
|
|
|
|
->setCouponCode('AWESOME')
|
|
|
|
|
->collectTotals();
|
|
|
|
|
|
|
|
|
|
$cart = cart()->getCart();
|
|
|
|
|
$cartItem = $cart->items()->first();
|
|
|
|
|
$cart = cart()->getCart();
|
|
|
|
|
$cartItem = $cart->items()
|
|
|
|
|
->first();
|
|
|
|
|
|
|
|
|
|
$I->assertEquals('AWESOME', $cartItem['coupon_code']);
|
|
|
|
|
$I->assertEquals(23.92, $cartItem['price']);
|
|
|
|
|
@ -680,9 +808,9 @@ class CartRuleCest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \Codeception\Example $scenario
|
|
|
|
|
* @param \Tests\Unit\Category\cartRuleWithCoupon $cartRuleWithCoupon
|
|
|
|
|
* @param int $cartID
|
|
|
|
|
* @param \Codeception\Example $scenario
|
|
|
|
|
* @param \Tests\Unit\Category\cartRuleWithCoupon $cartRuleWithCoupon
|
|
|
|
|
* @param int $cartID
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
@ -691,18 +819,10 @@ class CartRuleCest
|
|
|
|
|
$cartItems = [];
|
|
|
|
|
|
|
|
|
|
foreach ($scenario['productSequence'] as $key => $item) {
|
|
|
|
|
$pos = $this->array_find(
|
|
|
|
|
'product_id',
|
|
|
|
|
$this->products[$scenario['productSequence'][$key]]->id,
|
|
|
|
|
$cartItems
|
|
|
|
|
);
|
|
|
|
|
$pos = $this->array_find('product_id', $this->products[$scenario['productSequence'][$key]]->id, $cartItems);
|
|
|
|
|
|
|
|
|
|
if ($pos === null) {
|
|
|
|
|
$cartItem = new expectedCartItem(
|
|
|
|
|
$cartID,
|
|
|
|
|
$this->products[$scenario['productSequence'][$key]]->id
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$cartItem = new expectedCartItem($cartID, $this->products[$scenario['productSequence'][$key]]->id);
|
|
|
|
|
} else {
|
|
|
|
|
$cartItem = $cartItems[$pos];
|
|
|
|
|
$cartItem->quantity++;
|
|
|
|
|
@ -714,8 +834,8 @@ class CartRuleCest
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case self::PRODUCT_NOT_FREE:
|
|
|
|
|
$cartItem->price = self::PRODUCT_PRICE;
|
|
|
|
|
$cartItem->base_price = self::PRODUCT_PRICE;
|
|
|
|
|
$cartItem->price = self::PRODUCT_PRICE;
|
|
|
|
|
$cartItem->base_price = self::PRODUCT_PRICE;
|
|
|
|
|
$cartItem->tax_percent = self::TAX_RATE;
|
|
|
|
|
|
|
|
|
|
$cartItem->calcTotals();
|
|
|
|
|
@ -723,8 +843,8 @@ class CartRuleCest
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case self::PRODUCT_NOT_FREE_REDUCED_TAX:
|
|
|
|
|
$cartItem->price = self::REDUCED_PRODUCT_PRICE;
|
|
|
|
|
$cartItem->base_price = self::REDUCED_PRODUCT_PRICE;
|
|
|
|
|
$cartItem->price = self::REDUCED_PRODUCT_PRICE;
|
|
|
|
|
$cartItem->base_price = self::REDUCED_PRODUCT_PRICE;
|
|
|
|
|
$cartItem->tax_percent = self::REDUCED_TAX_RATE;
|
|
|
|
|
|
|
|
|
|
$cartItem->calcTotals();
|
|
|
|
|
@ -737,12 +857,7 @@ class CartRuleCest
|
|
|
|
|
case self::COUPON_FIXED:
|
|
|
|
|
foreach ($scenario['couponScenario']['products'] as $couponItem) {
|
|
|
|
|
if ($item === $couponItem) {
|
|
|
|
|
$cartItem->calcFixedDiscountAmounts(
|
|
|
|
|
self::DISCOUNT_AMOUNT_FIX,
|
|
|
|
|
self::DISCOUNT_AMOUNT_FIX,
|
|
|
|
|
$cartRuleWithCoupon->coupon->code,
|
|
|
|
|
$cartRuleWithCoupon->cartRule->id
|
|
|
|
|
);
|
|
|
|
|
$cartItem->calcFixedDiscountAmounts(self::DISCOUNT_AMOUNT_FIX, self::DISCOUNT_AMOUNT_FIX, $cartRuleWithCoupon->coupon->code, $cartRuleWithCoupon->cartRule->id);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -751,12 +866,7 @@ class CartRuleCest
|
|
|
|
|
case self::COUPON_FIXED_FULL:
|
|
|
|
|
foreach ($scenario['couponScenario']['products'] as $couponItem) {
|
|
|
|
|
if ($item === $couponItem) {
|
|
|
|
|
$cartItem->calcFixedDiscountAmounts(
|
|
|
|
|
self::DISCOUNT_AMOUNT_FIX_FULL,
|
|
|
|
|
self::DISCOUNT_AMOUNT_FIX_FULL,
|
|
|
|
|
$cartRuleWithCoupon->coupon->code,
|
|
|
|
|
$cartRuleWithCoupon->cartRule->id
|
|
|
|
|
);
|
|
|
|
|
$cartItem->calcFixedDiscountAmounts(self::DISCOUNT_AMOUNT_FIX_FULL, self::DISCOUNT_AMOUNT_FIX_FULL, $cartRuleWithCoupon->coupon->code, $cartRuleWithCoupon->cartRule->id);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -765,11 +875,7 @@ class CartRuleCest
|
|
|
|
|
case self::COUPON_PERCENTAGE:
|
|
|
|
|
foreach ($scenario['couponScenario']['products'] as $couponItem) {
|
|
|
|
|
if ($item === $couponItem) {
|
|
|
|
|
$cartItem->calcPercentageDiscountAmounts(
|
|
|
|
|
self::DISCOUNT_AMOUNT_PERCENT,
|
|
|
|
|
$cartRuleWithCoupon->coupon->code,
|
|
|
|
|
$cartRuleWithCoupon->cartRule->id
|
|
|
|
|
);
|
|
|
|
|
$cartItem->calcPercentageDiscountAmounts(self::DISCOUNT_AMOUNT_PERCENT, $cartRuleWithCoupon->coupon->code, $cartRuleWithCoupon->cartRule->id);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -778,11 +884,7 @@ class CartRuleCest
|
|
|
|
|
case self::COUPON_PERCENTAGE_FULL:
|
|
|
|
|
foreach ($scenario['couponScenario']['products'] as $couponItem) {
|
|
|
|
|
if ($item === $couponItem) {
|
|
|
|
|
$cartItem->calcPercentageDiscountAmounts(
|
|
|
|
|
100.0,
|
|
|
|
|
$cartRuleWithCoupon->coupon->code,
|
|
|
|
|
$cartRuleWithCoupon->cartRule->id
|
|
|
|
|
);
|
|
|
|
|
$cartItem->calcPercentageDiscountAmounts(100.0, $cartRuleWithCoupon->coupon->code, $cartRuleWithCoupon->cartRule->id);
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -792,14 +894,13 @@ class CartRuleCest
|
|
|
|
|
|
|
|
|
|
if ($pos === null) {
|
|
|
|
|
$cartItems[] = $cartItem;
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
$cartItems[$pos] = $cartItem;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if ($scenario['withCoupon'] && $scenario['couponScenario']['scenario'] === self::COUPON_FIXED_CART) {
|
|
|
|
|
$totals = $this->calcTotals($cartItems);
|
|
|
|
|
$totals = $this->calcTotals($cartItems);
|
|
|
|
|
$cartItems = $this->splitDiscountToItems($cartItems, $cartRuleWithCoupon, $totals);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -813,10 +914,10 @@ class CartRuleCest
|
|
|
|
|
'baseSubTotal' => 0.0,
|
|
|
|
|
];
|
|
|
|
|
foreach ($cartItems as $expectedCartItem) {
|
|
|
|
|
$result['subTotal'] += $expectedCartItem->total;
|
|
|
|
|
$result['subTotal'] += $expectedCartItem->total;
|
|
|
|
|
$result['baseSubTotal'] += $expectedCartItem->base_total;
|
|
|
|
|
}
|
|
|
|
|
$result['subTotal'] = round($result['subTotal'], expectedCart::CART_TOTAL_PRECISION);
|
|
|
|
|
$result['subTotal'] = round($result['subTotal'], expectedCart::CART_TOTAL_PRECISION);
|
|
|
|
|
$result['baseSubTotal'] = round($result['baseSubTotal'], expectedCart::CART_TOTAL_PRECISION);
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
@ -827,52 +928,44 @@ class CartRuleCest
|
|
|
|
|
cartRuleWithCoupon $cartRuleWithCoupon,
|
|
|
|
|
array $totals
|
|
|
|
|
): array {
|
|
|
|
|
$discountAmount = self::DISCOUNT_AMOUNT_CART;
|
|
|
|
|
$discountAmount = self::DISCOUNT_AMOUNT_CART;
|
|
|
|
|
$baseDiscountAmount = self::DISCOUNT_AMOUNT_CART;
|
|
|
|
|
// split coupon amount to cart items
|
|
|
|
|
$length = count($cartItems) - 1;
|
|
|
|
|
for ($i = 0; $i < $length; $i++) {
|
|
|
|
|
$cartItems[$i]->discount_amount = round(
|
|
|
|
|
self::DISCOUNT_AMOUNT_CART * $cartItems[$i]->total / $totals['subTotal'],
|
|
|
|
|
expectedCartItem::ITEM_DISCOUNT_AMOUNT_PRECISION
|
|
|
|
|
);
|
|
|
|
|
$discountAmount -= $cartItems[$i]->discount_amount;
|
|
|
|
|
$cartItems[$i]->discount_amount = round(self::DISCOUNT_AMOUNT_CART * $cartItems[$i]->total / $totals['subTotal'], expectedCartItem::ITEM_DISCOUNT_AMOUNT_PRECISION);
|
|
|
|
|
$discountAmount -= $cartItems[$i]->discount_amount;
|
|
|
|
|
|
|
|
|
|
$cartItems[$i]->base_discount_amount = round(
|
|
|
|
|
self::DISCOUNT_AMOUNT_CART * $cartItems[$i]->base_total / $totals['baseSubTotal'],
|
|
|
|
|
expectedCartItem::ITEM_DISCOUNT_AMOUNT_PRECISION
|
|
|
|
|
);
|
|
|
|
|
$baseDiscountAmount -= $cartItems[$i]->discount_amount;
|
|
|
|
|
$cartItems[$i]->base_discount_amount = round(self::DISCOUNT_AMOUNT_CART * $cartItems[$i]->base_total / $totals['baseSubTotal'], expectedCartItem::ITEM_DISCOUNT_AMOUNT_PRECISION);
|
|
|
|
|
$baseDiscountAmount -= $cartItems[$i]->discount_amount;
|
|
|
|
|
|
|
|
|
|
$cartItems[$i]->coupon_code = $cartRuleWithCoupon->coupon->code;
|
|
|
|
|
$cartItems[$i]->applied_cart_rule_ids = (string)$cartRuleWithCoupon->cartRule->id;
|
|
|
|
|
$cartItems[$i]->coupon_code = $cartRuleWithCoupon->coupon->code;
|
|
|
|
|
$cartItems[$i]->applied_cart_rule_ids = (string) $cartRuleWithCoupon->cartRule->id;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$cartItems[$length]->discount_amount = $discountAmount;
|
|
|
|
|
$cartItems[$length]->discount_amount = $discountAmount;
|
|
|
|
|
$cartItems[$length]->base_discount_amount = $baseDiscountAmount;
|
|
|
|
|
|
|
|
|
|
$cartItems[$length]->coupon_code = $cartRuleWithCoupon->coupon->code;
|
|
|
|
|
$cartItems[$length]->applied_cart_rule_ids = (string)$cartRuleWithCoupon->cartRule->id;
|
|
|
|
|
$cartItems[$length]->coupon_code = $cartRuleWithCoupon->coupon->code;
|
|
|
|
|
$cartItems[$length]->applied_cart_rule_ids = (string) $cartRuleWithCoupon->cartRule->id;
|
|
|
|
|
|
|
|
|
|
return $cartItems;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $expectedCartItems
|
|
|
|
|
* @param array $expectedCartItems
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private function checkMaxDiscount(array $expectedCartItems): array
|
|
|
|
|
{
|
|
|
|
|
foreach ($expectedCartItems as $key => $cartItem) {
|
|
|
|
|
$itemGrandTotal = round($cartItem->total + $cartItem->tax_amount,
|
|
|
|
|
expectedCartItem::ITEM_DISCOUNT_AMOUNT_PRECISION);
|
|
|
|
|
$itemGrandTotal = round($cartItem->total + $cartItem->tax_amount, expectedCartItem::ITEM_DISCOUNT_AMOUNT_PRECISION);
|
|
|
|
|
if ($cartItem->discount_amount > $itemGrandTotal) {
|
|
|
|
|
$expectedCartItems[$key]->discount_amount = $itemGrandTotal;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$itemBaseGrandTotal = round($cartItem->base_total + $cartItem->base_tax_amount,
|
|
|
|
|
expectedCartItem::ITEM_DISCOUNT_AMOUNT_PRECISION);
|
|
|
|
|
$itemBaseGrandTotal = round($cartItem->base_total + $cartItem->base_tax_amount, expectedCartItem::ITEM_DISCOUNT_AMOUNT_PRECISION);
|
|
|
|
|
if ($cartItem->base_discount_amount > $itemBaseGrandTotal) {
|
|
|
|
|
$expectedCartItems[$key]->base_discount_amount = $itemBaseGrandTotal;
|
|
|
|
|
}
|
|
|
|
|
@ -882,37 +975,33 @@ class CartRuleCest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param int $cartId
|
|
|
|
|
* @param array $expectedCartItems
|
|
|
|
|
* @param int $cartId
|
|
|
|
|
* @param array $expectedCartItems
|
|
|
|
|
*
|
|
|
|
|
* @param \Tests\Unit\Category\cartRuleWithCoupon $cartRuleWithCoupon
|
|
|
|
|
* @param \Tests\Unit\Category\cartRuleWithCoupon $cartRuleWithCoupon
|
|
|
|
|
*
|
|
|
|
|
* @return \Tests\Unit\Category\expectedCart
|
|
|
|
|
*/
|
|
|
|
|
private function getExpectedCart(int $cartId, array $expectedCartItems, ?cartRuleWithCoupon $cartRuleWithCoupon): expectedCart
|
|
|
|
|
{
|
|
|
|
|
$cart = new expectedCart(
|
|
|
|
|
$cartId,
|
|
|
|
|
auth()->guard('customer')->user()->id
|
|
|
|
|
);
|
|
|
|
|
$cart = new expectedCart($cartId, auth()
|
|
|
|
|
->guard('customer')
|
|
|
|
|
->user()->id);
|
|
|
|
|
|
|
|
|
|
if ($cartRuleWithCoupon) {
|
|
|
|
|
$cart->applyCoupon(
|
|
|
|
|
$cartRuleWithCoupon->cartRule->id,
|
|
|
|
|
$cartRuleWithCoupon->coupon->code
|
|
|
|
|
);
|
|
|
|
|
$cart->applyCoupon($cartRuleWithCoupon->cartRule->id, $cartRuleWithCoupon->coupon->code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
foreach ($expectedCartItems as $cartItem) {
|
|
|
|
|
$cart->items_count++;
|
|
|
|
|
$cart->items_qty += $cartItem->quantity;
|
|
|
|
|
|
|
|
|
|
$cart->sub_total += $cartItem->total;
|
|
|
|
|
$cart->tax_total += $cartItem->tax_amount;
|
|
|
|
|
$cart->sub_total += $cartItem->total;
|
|
|
|
|
$cart->tax_total += $cartItem->tax_amount;
|
|
|
|
|
$cart->discount_amount += $cartItem->discount_amount;
|
|
|
|
|
|
|
|
|
|
$cart->base_sub_total += $cartItem->base_total;
|
|
|
|
|
$cart->base_tax_total += $cartItem->base_tax_amount;
|
|
|
|
|
$cart->base_sub_total += $cartItem->base_total;
|
|
|
|
|
$cart->base_tax_total += $cartItem->base_tax_amount;
|
|
|
|
|
$cart->base_discount_amount += $cartItem->base_discount_amount;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -922,13 +1011,13 @@ class CartRuleCest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \UnitTester $I
|
|
|
|
|
* @param \UnitTester $I
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
private function generateTaxCategories(UnitTester $I): array
|
|
|
|
|
{
|
|
|
|
|
$result = [];
|
|
|
|
|
$result = [];
|
|
|
|
|
$country = strtoupper(Config::get('app.default_country')) ?? 'DE';
|
|
|
|
|
foreach ($this->getTaxRateSpecifications() as $taxSpec => $taxRate) {
|
|
|
|
|
$tax = $I->have(TaxRate::class, [
|
|
|
|
|
@ -950,20 +1039,20 @@ class CartRuleCest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \UnitTester $I
|
|
|
|
|
* @param array $scenario
|
|
|
|
|
* @param array $taxCategories
|
|
|
|
|
* @param \UnitTester $I
|
|
|
|
|
* @param array $scenario
|
|
|
|
|
* @param array $taxCategories
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
* @throws \Exception
|
|
|
|
|
*/
|
|
|
|
|
private function generateProducts(UnitTester $I, array $scenario, array $taxCategories): array
|
|
|
|
|
{
|
|
|
|
|
$products = [];
|
|
|
|
|
$products = [];
|
|
|
|
|
$productSpecs = $this->getProductSpecifications();
|
|
|
|
|
|
|
|
|
|
foreach ($scenario as $item) {
|
|
|
|
|
$productConfig = $this->makeProductConfig($productSpecs[$item], $taxCategories);
|
|
|
|
|
$productConfig = $this->makeProductConfig($productSpecs[$item], $taxCategories);
|
|
|
|
|
$products[$item] = $I->haveProduct($productSpecs[$item]['productType'], $productConfig);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@ -971,8 +1060,8 @@ class CartRuleCest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param \UnitTester $I
|
|
|
|
|
* @param array $couponConfig
|
|
|
|
|
* @param \UnitTester $I
|
|
|
|
|
* @param array $couponConfig
|
|
|
|
|
*
|
|
|
|
|
* @return \Tests\Unit\Category\cartRuleWithCoupon
|
|
|
|
|
*/
|
|
|
|
|
@ -981,44 +1070,39 @@ class CartRuleCest
|
|
|
|
|
$faker = Factory::create();
|
|
|
|
|
|
|
|
|
|
$couponSpecifications = $this->getCouponSpecifications();
|
|
|
|
|
$ruleConfig = $this->makeRuleConfig(
|
|
|
|
|
$couponSpecifications[$couponConfig['scenario']],
|
|
|
|
|
$this->products,
|
|
|
|
|
$couponConfig['products']
|
|
|
|
|
);
|
|
|
|
|
$cartRule = $I->have(CartRule::class, $ruleConfig);
|
|
|
|
|
$ruleConfig = $this->makeRuleConfig($couponSpecifications[$couponConfig['scenario']], $this->products, $couponConfig['products']);
|
|
|
|
|
$cartRule = $I->have(CartRule::class, $ruleConfig);
|
|
|
|
|
|
|
|
|
|
DB::table('cart_rule_channels')->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'channel_id' => core()->getCurrentChannel()->id,
|
|
|
|
|
]);
|
|
|
|
|
DB::table('cart_rule_channels')
|
|
|
|
|
->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'channel_id' => core()->getCurrentChannel()->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$guestCustomerGroup = $I->grabRecord('customer_groups', ['code' => 'guest']);
|
|
|
|
|
DB::table('cart_rule_customer_groups')->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'customer_group_id' => $guestCustomerGroup['id'],
|
|
|
|
|
]);
|
|
|
|
|
DB::table('cart_rule_customer_groups')
|
|
|
|
|
->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'customer_group_id' => $guestCustomerGroup['id'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$generalCustomerGroup = $I->grabRecord('customer_groups', ['code' => 'general']);
|
|
|
|
|
DB::table('cart_rule_customer_groups')->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'customer_group_id' => $generalCustomerGroup['id'],
|
|
|
|
|
]);
|
|
|
|
|
DB::table('cart_rule_customer_groups')
|
|
|
|
|
->insert([
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
'customer_group_id' => $generalCustomerGroup['id'],
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
$coupon = $I->have(CartRuleCoupon::class, [
|
|
|
|
|
'cart_rule_id' => $cartRule->id,
|
|
|
|
|
]);
|
|
|
|
|
|
|
|
|
|
return new cartRuleWithCoupon(
|
|
|
|
|
$cartRule,
|
|
|
|
|
$coupon
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
return new cartRuleWithCoupon($cartRule, $coupon);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $productSpec
|
|
|
|
|
* @param array $taxCategories
|
|
|
|
|
* @param array $productSpec
|
|
|
|
|
* @param array $taxCategories
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
@ -1052,9 +1136,9 @@ class CartRuleCest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param array $ruleSpec
|
|
|
|
|
* @param array $products
|
|
|
|
|
* @param array $couponableProducts
|
|
|
|
|
* @param array $ruleSpec
|
|
|
|
|
* @param array $products
|
|
|
|
|
* @param array $couponableProducts
|
|
|
|
|
*
|
|
|
|
|
* @return array
|
|
|
|
|
*/
|
|
|
|
|
@ -1151,9 +1235,9 @@ class CartRuleCest
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @param string $param
|
|
|
|
|
* @param string $param
|
|
|
|
|
* @param $needleValue
|
|
|
|
|
* @param array $data
|
|
|
|
|
* @param array $data
|
|
|
|
|
*
|
|
|
|
|
* @return int|null
|
|
|
|
|
*/
|
|
|
|
|
|