/** * checks for Combination Products and makes sure that enough of the component products are added. * */ protected function addProductsPerCombo() { $reload = false; $shoppingCart = ShoppingCart::singleton(); $combinationProductOrderItems = $this->loadCombinationProducts(); if ($combinationProductOrderItems->count()) { foreach ($combinationProductOrderItems as $combinationProductOrderItem) { $combinationProduct = $combinationProductOrderItem->Buyable(); $comboProductQTY = $combinationProductOrderItem->Quantity; $includedProducts = $combinationProduct->IncludedProducts(); if ($includedProducts) { foreach ($includedProducts as $includedProduct) { $includedProductQTY = $this->countOfProductInOrder($includedProduct); $difference = $comboProductQTY - $includedProductQTY; if ($difference) { $reload = true; if ($comboProductQTY) { //in case it has not been added if (!$includedProduct->IsInCart()) { $includedProduct->setAlternativeClassNameForOrderItem("IncludedProduct_OrderItem"); $item = $shoppingCart->addBuyable($includedProduct); if ($item) { $item->ParentOrderItemID = $combinationProductOrderItem->ID; $item->write(); } } $shoppingCart->setQuantity($includedProduct, $comboProductQTY); } else { $shoppingCart->deleteBuyable($includedProduct); } } } } } } if ($reload) { CartResponse::set_force_reload(); } }
/** * Sets the $force_reload to true; */ public static function set_force_reload() { self::$force_reload = true; }
function onBeforeDelete() { parent::onBeforeDelete(); CartResponse::set_force_reload(); }