@@ -55,7 +55,50 @@ public function product_catalog_price_rules_apply()
5555 #[Test]
5656 public function product_can_have_tier_prices ()
5757 {
58- $ this ->assertTrue (true );
59- // TODO: Base DB doesn't have tier prices. Test this some other way.
58+ $ product = Product::find (4 );
59+
60+ $ product ->tierPrices ()->create (['qty ' => 5 , 'value ' => 40 , 'website_id ' => 1 , 'all_groups ' => 1 , 'customer_group_id ' => 0 ]);
61+ $ product ->tierPrices ()->create (['qty ' => 10 , 'value ' => 35 , 'website_id ' => 1 , 'all_groups ' => 1 , 'customer_group_id ' => 0 ]);
62+ $ product ->tierPrices ()->create (['qty ' => 15 , 'value ' => 40 , 'website_id ' => 1 , 'all_groups ' => 1 , 'customer_group_id ' => 0 ]);
63+
64+ $ product ->tierPrices ()->create (['qty ' => 1 , 'value ' => 43 , 'website_id ' => 1 , 'all_groups ' => 0 , 'customer_group_id ' => 2 ]);
65+ $ product ->tierPrices ()->create (['qty ' => 5 , 'value ' => 39 , 'website_id ' => 1 , 'all_groups ' => 0 , 'customer_group_id ' => 2 ]);
66+ $ product ->tierPrices ()->create (['qty ' => 15 , 'value ' => 34 , 'website_id ' => 1 , 'all_groups ' => 0 , 'customer_group_id ' => 2 ]);
67+
68+ $ product ->tierPrices ()->create (['qty ' => 20 , 'value ' => 30 , 'website_id ' => 0 , 'all_groups ' => 1 , 'customer_group_id ' => 0 ]);
69+
70+ // All groups
71+ $ this ->assertEquals (45 * 4 , $ product ->getPrice (4 ), 'Tier price for all groups, qty 4 ' );
72+ $ this ->assertEquals (40 * 5 , $ product ->getPrice (5 ), 'Tier price for all groups, qty 5 ' );
73+ $ this ->assertEquals (35 * 12 , $ product ->getPrice (12 ), 'Tier price for all groups, qty 12 ' );
74+ $ this ->assertEquals (35 * 15 , $ product ->getPrice (15 ), 'Tier price for all groups, qty 15 ' );
75+ $ this ->assertEquals (30 * 23 , $ product ->getPrice (23 ), 'Tier price for all groups, qty 23 ' );
76+
77+ // Specifically customer group 2
78+ $ this ->assertEquals (43 * 4 , $ product ->getPrice (4 , 2 ), 'Tier price for group 2, qty 4 ' );
79+ $ this ->assertEquals (39 * 5 , $ product ->getPrice (5 , 2 ), 'Tier price for group 2, qty 5 ' );
80+ $ this ->assertEquals (35 * 12 , $ product ->getPrice (12 , 2 ), 'Tier price for group 2, qty 12 ' );
81+ $ this ->assertEquals (34 * 15 , $ product ->getPrice (15 , 2 ), 'Tier price for group 2, qty 15 ' );
82+ $ this ->assertEquals (30 * 22 , $ product ->getPrice (22 , 2 ), 'Tier price for group 2, qty 22 ' );
83+
84+ // This is technically not valid, but without creating a whole new website this is the best we can do in a unit test.
85+ config ()->set ('rapidez.website ' , 0 );
86+ $ this ->assertEquals (45 * 15 , $ product ->getPrice (15 , 2 ), 'Tier price on website 0 for group 2, qty 15 ' );
87+ $ this ->assertEquals (45 * 15 , $ product ->getPrice (15 ), 'Tier price on website 0 for all groups, qty 15 ' );
88+ $ this ->assertEquals (30 * 21 , $ product ->getPrice (21 ), 'Tier price on website 0 for all groups, qty 21 ' );
89+ }
90+
91+ #[Test]
92+ public function product_can_combine_tier_prices_and_special_price ()
93+ {
94+ $ product = Product::find (10 );
95+
96+ $ product ->tierPrices ()->create (['qty ' => 5 , 'value ' => 30 , 'website_id ' => 1 , 'all_groups ' => 1 , 'customer_group_id ' => 0 ]);
97+ $ product ->tierPrices ()->create (['qty ' => 10 , 'value ' => 20 , 'website_id ' => 1 , 'all_groups ' => 1 , 'customer_group_id ' => 0 ]);
98+
99+ // All groups
100+ $ this ->assertEquals (24 * 4 , $ product ->getPrice (4 ), 'Tier price (should be special price) for all groups, qty 4 ' );
101+ $ this ->assertEquals (24 * 5 , $ product ->getPrice (5 ), 'Tier price (should be special price) for all groups, qty 5 ' );
102+ $ this ->assertEquals (20 * 12 , $ product ->getPrice (12 ), 'Tier price for all groups, qty 12 ' );
60103 }
61104}
0 commit comments