<?php

namespace YSquare\GiftCert\Model;

use OxidEsales\Eshop\Core\Registry;

class Article extends Article_parent{

    /**
     * Check if the article is a gift certificate
     * @return bool
     */
    public function isGiftCertArticle(){
        // Is the article itself a giftcert article?
        // Well then we go for it
        if($this->oxarticles__ys_giftcert->value > 0){
            return true;
        }

        // If the article is a child and the parent is a giftcert
        // we also treat the child as a giftcert
        $oParent = $this->getParentArticle();
        if($oParent && $oParent->oxarticles__ys_giftcert->value > 0){
            return true;
        }

        return false;
    }

    public function isOfflineGiftCert() {
        // Is this article marked as an explicit offline giftcert...
        if($this->oxarticles__ys_giftcert_offline->value > 0){
            return true;
        }

        // ... or is his parent ...
        $oParent = $this->getParentArticle();
        if($oParent && $oParent->oxarticles__ys_giftcert_offline->value > 0){
            return true;
        }

        // ... or not at all?
        return false;
    }

    public function getMinGiftcertValue() {
        $value = Registry::getConfig()->getConfigParam('dYsGiftcertMinValue');
        $value = round($value,2);
        return $value;
    }
}