<?php

if (! function_exists('discount_prosent')){
    function discount_prosent($product){
        $productTypeInstance = $product->getTypeInstance();
        $discount = 0;
        switch($product->type) {
            case 'configurable':
                if ($productTypeInstance->haveOffer()) {
                    $discount = 100 - $productTypeInstance->getOfferPrice()*100/$productTypeInstance->getMinimalPrice();
                }
                break;
            case 'simple':
                if ($productTypeInstance->haveSpecialPrice()) {
                    $discount = 100 - $productTypeInstance->getMinimalPrice()*100/$product->price;
                }
                break;
        }

        return ceil($discount);
    }
}

if(! function_exists('priceHtml')){
    function priceHtml($product){
        $productTypeInstance = $product->getTypeInstance();
        switch($product->type){
            case 'configurable':
                if ($productTypeInstance->haveOffer()) {
                    return '<span class="item-gallery-price-old">' . core()->currency($productTypeInstance->evaluatePrice($productTypeInstance->getMinimalPrice())) . '</span>'
                        . '<span class="item-gallery-price-new">' . core()->currency($productTypeInstance->evaluatePrice($productTypeInstance->getOfferPrice())) . '</span>';
                } else {
                    return '<span class="item-gallery-price-new">' . core()->currency($productTypeInstance->evaluatePrice($productTypeInstance->getMinimalPrice())) . '</span>';
                }
            case 'simple':
                if ($productTypeInstance->haveSpecialPrice()) {
                    return  '<span class="item-gallery-price-old">' . core()->currency($productTypeInstance->evaluatePrice($product->price)) . '</span>'
                        . '<span class="item-gallery-price-new">' . core()->currency($productTypeInstance->evaluatePrice($productTypeInstance->getSpecialPrice())) . '</span>';
                } else {
                    return '<span class="item-gallery-price-new">' . core()->currency($productTypeInstance->evaluatePrice($product->price)) . '</span>';
                }
            default:
                return '<span class="item-gallery-price-new">' . core()->currency($productTypeInstance->evaluatePrice($productTypeInstance->getMinimalPrice())) . '</span>';
        }

    }
}

