/** * Test cart when a product becomes unavailable (deleted / out of stock) * after the user has already added it to the cart */ public function testCartTotal_WithUnavailableProducts() { $module_srl = 107; $cart_srl = 774; $deleted_product_srl = 133; // Act: delete one product from xe_products but keep it in cart $product_repository = new ProductRepository(); $args = new stdClass(); $args->product_srl = $deleted_product_srl; $product_repository->deleteProduct($args); $cart = new Cart($cart_srl); // Assert // 1. Check that cart has expected products $this->assertEquals(1, count($cart->getProducts(NULL, TRUE))); // When $onlyAvailable is true, count just availablel products $this->assertEquals(2, count($cart->getProducts())); // Default, , show all products // 3. Check that item total is correct $this->assertEquals(29.99, $cart->getItemTotal()); // Count just available products // 4. Check global total is correct (includes shipping +10) $this->assertEquals(39.99, $cart->getTotal(), '', 0.01); // Count just available products }
public function testProductCountUpdatesOnProductDelete() { $module_srl = 1001; $product_repository = new ProductRepository(); $product = new SimpleProduct(); $product->product_srl = 12; $product->title = "Some product"; $product->member_srl = 4; $product->module_srl = $module_srl; $product->product_type = 'simple'; $product->sku = 'some-product'; $product->friendly_url = $product->sku; $product->price = 100; $product->categories[] = 1000; $product->categories[] = 1002; $product_repository->insertProduct($product); // Check that count was increased $category_repository = new CategoryRepository(); $category = $category_repository->getCategory(1000); $this->assertEquals(1, $category->product_count); // Check that count was increased $category = $category_repository->getCategory(1002); $this->assertEquals(1, $category->product_count); // Delete product $args = new stdClass(); $args->module_srl = $module_srl; $products = $product_repository->getAllProducts($args); $this->assertNotNull($products); $product = array_shift($products); $args = new stdClass(); $args->product_srl = $product->product_srl; $product_repository->deleteProduct($args); // Check that count was decreased $category_repository = new CategoryRepository(); $category = $category_repository->getCategory(1000); $this->assertEquals(0, $category->product_count); // Check that count was decreased $category = $category_repository->getCategory(1002); $this->assertEquals(0, $category->product_count); }