<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>Option to product - Journal 3 Compatibility</name>
    <code>option_to_product_journal_3_compatibility_ocmod</code>
    <version>1.0.0</version>
    <author>DevmanExtensions</author>
	<link>https://www.devmanextensions.com</link>
    <file error="skip" path="catalog/view/theme/journal3/template/product/product.twig">
        <operation error="skip">
            <search trim="true"><![CDATA[<h3 class="options-title title">{{ text_option }}</h3>]]></search>
            <add position="after"><![CDATA[
                <script type="text/javascript" src="catalog/view/javascript/option_to_product/template_compatibility.js"></script>
                <script type="text/javascript">
                    var product_data_selector = $('#product');
                    var product_prices_container = $('div.product-price-group');
                    var product_price_selector = 'div.product-price-group div.price-group div.product-price:not(.price-new)';
                    var product_price_old = 'div.product-price-group div.price-group div.product-price-old';
                    var product_price_new = 'div.product-price-group div.price-group div.product-price-new';
                    var product_price_tax = 'div.product-price-group div.product-tax';
                    var tax_enabled = $(product_price_tax).is(":visible");
                    var button_cart_selector = '#button-cart';
                    var input_quantity_selector = 'input[name="quantity"]';
                    var gallery_main_image_selector = $('div.product-image div.main-image div.swiper-wrapper');
                    var gallery_additional_images_selector = $('div.product-image div.additional-images div.swiper-wrapper');
                    var gallery_selector = '';
                </script>
                {{ html_option_combinations }}
            ]]></add>
        </operation>
        <operation error="skip">
            <search trim="true"><![CDATA[{{ footer }}]]></search>
            <add position="before"><![CDATA[{{ script_footer }}]]></add>
        </operation>
        <operation error="skip">
            <search trim="true"><![CDATA[<div class="product-price">{{ special }}</div>]]></search>
            <add position="replace"><![CDATA[<div class="product-price price-new">{{ special }}</div>]]></add>
        </operation>

        <operation error="skip">
            <search trim="true"><![CDATA[{% if not special %}]]></search>
            <add position="replace"><![CDATA[
                    {% if starting_from %}
                        <div class="product-price">{{ starting_from }}</div>
                    {% elseif not special %}]]></add>
        </operation>
        <operation error="skip">
            <search trim="true"><![CDATA[{{ model }}]]></search>
            <add position="replace"><![CDATA[<span id="otp-model">{{ model }}</span>]]></add>
        </operation>
        <operation error="skip">
            <search trim="true"><![CDATA[{{ stock }}]]></search>
            <add position="replace"><![CDATA[<span id="otp-stock">{{ stock }}</span></li>
                {% if config_otp_extra %}
                    <li><span id="otp-extra"></span></li>
                {% endif %}
                {% if config_otp_dimensions %}
                    <li><span id="otp-dimensions"></span></li>
                {% endif %}]]></add>
        </operation>
        <operation error="skip">
            <search trim="true"><![CDATA[{{ reward }}]]></search>
            <add position="replace"><![CDATA[<span id="otp-reward">{{ reward }}</span>]]></add>
        </operation>
        <operation error="skip">
            <search trim="true"><![CDATA[{% if options %}]]></search>
            <add position="replace"><![CDATA[{% if options or otp_options %}]]></add>
        </operation>

        <!--<operation error="skip">
            <search trim="true"><![CDATA[$('.thumbnails').magnificPopup({]]></search>
            <add position="replace"><![CDATA[$('.thumbnails .image-additional').magnificPopup({]]></add>
        </operation>-->

        <operation error="skip">
            <search trim="true"><![CDATA[$('#button-cart').on('click', function () {]]></search>
            <add position="after"><![CDATA[{% if otp_options %}
                    if ($('#button-cart').hasClass('inactive')) {
                        return false;
                    }
                {% endif %}]]></add>
        </operation>
    </file>
    <file error="skip" path="catalog/view/theme/journal3/template/journal3/product_card.twig">
        <operation error="skip">
            <search trim="true" index="0"><![CDATA[{% if product.labels %}]]></search>
            <add position="before" offset="1"><![CDATA[{% if product.otp_bullets %}<div class="otp_bullets">{{ product.otp_bullets }}</div>{% endif %}]]></add>
        </operation>
        <operation error="skip">
            <search trim="true"><![CDATA[{% if product.special %}]]></search>
            <add position="replace"><![CDATA[{% if product.starting_from %}{{ product.starting_from }}{% elseif product.special %}]]></add>
        </operation>
    </file>
    <file error="skip" path="catalog/model/journal3/product.php">
        <operation error="skip" info="Add _constructor method to load OptionToProduct model and more">
            <search trim="true"><![CDATA[class ModelJournal3Product extends Model {]]></search>
            <add position="after"><![CDATA[
                public function __construct($registry) {
                    parent::__construct($registry);
                    $loader = new Loader($registry);
                    $loader->model('extension/module/option_to_product');
                }
            ]]></add>
        </operation>
        <operation error="skip">
            <search trim="true" index="0"><![CDATA[foreach ($query->rows as $row) {]]></search>
            <add position="after"><![CDATA[$starting_from = $this->model_extension_module_option_to_product->getStartingFrom($row['product_id'], $row['price'], $row['special']);]]></add>
        </operation>
        <operation error="skip">
            <search trim="true"><![CDATA[($row['discount'] ? $row['discount'] : $row['price']),]]></search>
            <add position="replace"><![CDATA[
                ($row['discount'] && !$starting_from ? $row['discount'] : $row['price']),
                'starting_from' => $starting_from,
            ]]></add>
        </operation>
    </file>
</modification>