<?php

namespace YSquare\GiftCert\Model;

class BasketItem extends BasketItem_parent{

    /**
     * Sets $this->_oPrice
     *
     * @param object $oPrice price
     */
    public function setPrice($oPrice)
    {
        $oArticle = $this->getArticle();
        $isGiftCert = $oArticle && method_exists($oArticle, 'isGiftCertArticle') && $oArticle->isGiftCertArticle();

        if(!$this->isAdmin()){
            if($isGiftCert){
                $aPersParam = $this->getPersParams();
                if(isset($aPersParam['details']) && !empty($aPersParam['details'])){
                    $dPrice = str_replace(",", ".", $aPersParam['details']);
                    $oPrice->setPrice($dPrice);
                    return parent::setPrice($oPrice);
                }
            }
        }

        return parent::setPrice($oPrice);
    }

    public function isGiftCertArticle() {
        $oArticle = $this->getArticle();
        return $oArticle && method_exists($oArticle, 'isGiftCertArticle') && $oArticle->isGiftCertArticle();
    }
}