<?xml version="1.0" encoding="UTF-8"?>

<!--
ALTER TABLE product
ADD cfnotice VARCHAR( 5 ) CHARACTER SET utf8 COLLATE utf8_bin NOT NULL
AFTER model
-->

<modification>
    <id><![CDATA[Carbon Fiber Notice]]></id>
    <version><![CDATA[1.0]]></version>
    <vqmver><![CDATA[]]></vqmver>
    <author><![CDATA[Jason Aguilar - Wed, September 4 2014]]></author>

    <file name="admin/controller/catalog/product.php">
        <operation>
            <search position="before"><![CDATA[
                $this->load->model('setting/store');
                ]]></search>
            <add><![CDATA[// CF Notice Plugin
                if (isset($this->request->post['cfnotice'])) {
                    $this->data['cfnotice'] = $this->request->post['cfnotice'];
                } else if (isset($product_info)) {
                    $this->data['cfnotice'] = $product_info['cfnotice'];
                } else {
                    $this->data['cfnotice'] = '';
                }
                ]]></add>
        </operation>
    </file>

    <file name="admin/model/catalog/product.php">
        <operation>
            <search position="replace"><![CDATA[
            stock_status_id = '" . (int)$data['stock_status_id'] . "',
            ]]></search>
            <add><![CDATA[
          stock_status_id = '" . (int)$data['stock_status_id'] . "', cfnotice = '" . $this->db->escape($data['cfnotice']) . "',
            ]]></add>
        </operation>

    </file>
    <file name="admin/view/template/catalog/product_form.tpl">
        <operation>
            <search position="replace"><![CDATA[
            <td><?php echo $entry_download; ?></td>
            ]]></search>
            <add><![CDATA[
          <td>Add Carbon Fiber Notice?:</td>
            <td>
            <div class="exeliocf">
            <label><input type="radio" name="cf" id="exelcf1" value="Yes" <?php if ($cfnotice == 'Yes') { ?> checked="checked" <?php } ?>> Yes</label>
            <label><input type="radio" name="cf" id="exelcf2" value="No" <?php if ($cfnotice != 'Yes') { ?> checked="checked" <?php } ?>> No</label>
            </div>

            <input style="display:none;" type="text" name="cfnotice" id="cfnotice" value="<?php echo $cfnotice; ?>" />
            </td>
            </tr>
            <script type="text/javascript">
            $(document).ready(function(){

            $('input[name=cf]:radio').change(function () {
            if ($(this).val() == "Yes") {
                // Disable your element here
                $('#cfnotice').val('Yes');
            } else {
                // Re-enable here I guess
                $('#cfnotice').val('No');
            }
            });
            });
            </script>
            <tr>
            <td><?php echo $entry_download; ?></td>      
        ]]></add>
        </operation>
    </file>
    <file name="catalog/controller/checkout/cart.php">

        <operation info="Add Query to Cart File">
            <search position="after"><![CDATA[
            'stock'    => $result['stock'],
            ]]></search>
            <add><![CDATA[
            'cfnotice' => $result['cfnotice'],
            ]]></add>
        </operation>
        
    </file>

    <file name="system/library/cart.php">

        <operation info="Add Query to Cart File">
            <search position="before"><![CDATA[
            'tax_class_id' => $product_query->row['tax_class_id'],
            ]]></search>
            <add><![CDATA[
            'cfnotice'     => $product_query->row['cfnotice'],
            ]]></add>
        </operation>
        
    </file>

    <file name="catalog/view/theme/default/template/checkout/cart.tpl">

        <operation info="Add Query to Cart File">
            <search position="before"><![CDATA[
            <?php echo $footer; ?> 
            ]]></search>
            <add><![CDATA[
            <?php
            $notice = 0; $count = 0; foreach ($products as $product) { if($product['cfnotice'] == 'Yes') { $notice = 1; $count = $count + 1; } } if($notice == 1) { ?>
            <section id="cfnotice" style="margin-bottom: 40px;">
                <div class="container">
                    <br />
                    <b>Please note!</b> 
                    <br />
                    Due to the limited numbers, high handling costs and the delicate nature of carbon fiber products and the fact that each piece is prepped, clear coated and buffed prior to shipping; a 20% restocking fee will apply to any returns on the <?php echo $count; ?> carbon fiber item(s) in your cart. Our standard return policy does not apply to carbon fiber products. If you have any questions please ask prior to ordering.
                    <br />
                </div>
            </section>
            <?php } ?>
            ]]></add>
        </operation>
    </file>

</modification>
