<?php

namespace YSquare\GiftCert\Core;

use OxidEsales\Eshop\Core\Registry;

class ViewConfig extends ViewConfig_parent
{
    protected $businessGiftcertCleanBasket = null;

    public function isGiftcertBusinessCleanBasket()
    {
        if ($this->businessGiftcertCleanBasket === null) {
            $session = Registry::getSession();
            $basket = $session->getBasket();
            // check if we have only Business Giftcerts in Basket, otherwise show error

            $items = $basket->getContents();
            $hasNormalArticle = false;
            $hasBusinessGiftcert = false;

            foreach ($items as $basketitem) {
                $article = $basketitem->getArticle();
                if ($article->isBusinessGiftCert()) {
                    $hasBusinessGiftcert = true;
                } else {
                    $hasNormalArticle = true;
                }
            }

            if ($hasBusinessGiftcert && $hasNormalArticle) {
                $this->businessGiftcertCleanBasket = false;
            } else {
                $this->businessGiftcertCleanBasket = true;
            }
        }
        return $this->businessGiftcertCleanBasket;
    }
}