/** * Returns if this method can be used with the current cart. * * @param EventgalleryLibraryLineitemcontainer $cart * * @return bool */ public function isEligible($cart) { // if there is no rule, this method is valued if (!isset($this->getData()->rules)) { return true; } $itemCountBased = isset($this->getData()->rules->type) && $this->getData()->rules->type == 'itemcount'; if ($itemCountBased) { // if the minimum amount is not defined skip this if (isset($this->getData()->rules->minAmount)) { // if the item count is not high enough if ($cart->getLineItemsTotalCount() < $this->getData()->rules->minAmount) { return false; } } // if the maximum amount is not defined skip this if (isset($this->getData()->rules->maxAmount) && $this->getData()->rules->maxAmount > 0) { // if the item count is too high if ($cart->getLineItemsTotalCount() > $this->getData()->rules->maxAmount) { return false; } } } else { // if the minimum amount is not defined skip this if (isset($this->getData()->rules->minAmount)) { // if the subtotal is not high enough if ($cart->getSubTotal()->getAmount() < $this->getData()->rules->minAmount) { return false; } } // if the maximum amount is not defined skip this if (isset($this->getData()->rules->maxAmount) && $this->getData()->rules->maxAmount > 0) { // if the subtotal is too high if ($cart->getSubTotal()->getAmount() > $this->getData()->rules->maxAmount) { return false; } } } return true; }