<?php

namespace YSquare\GiftCert\Model;

use OxidEsales\Eshop\Core\Field;

class OrderArticle extends OrderArticle_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->oxorderarticles__ys_giftcert->value > 0) {
            return true;
        }
        return false;
    }

    /**
     * Copies passed to method product into $this.
     *
     * @param object $oProduct product to copy
     */
    public function copyThis($oProduct)
    {
        $parent_return = parent::copyThis($oProduct);

        // we have to check article itself and parent if giftcerts are variants
        if ($oProduct->isGiftcertArticle()) {
            $this->oxorderarticles__ys_giftcert = new Field(1);
        } else {
            $this->oxorderarticles__ys_giftcert = new Field(0);
        }
        return $parent_return;
    }
}
