<?xml version="1.0" encoding="UTF-8"?>
<!-- ALTER TABLE  `product` ADD  `xoffnext` DECIMAL( 15, 4 ) NOT NULL DEFAULT '0.0000' AFTER  `price` ; -->
<modification>
    <id><![CDATA[X off your next purchase!]]></id>
    <version><![CDATA[1.0]]></version>
    <vqmver><![CDATA[]]></vqmver>
    <author><![CDATA[Jason Aguilar - Wed, Aug 27 2014]]></author>

    <file name="admin/controller/catalog/product.php">
        <operation>
            <search position="before"><![CDATA[
                if (isset($this->request->post['height'])) {
                ]]></search>
            <add><![CDATA[// Core Charge Plugin
                if (isset($this->request->post['xoffnext'])) {
                    $this->data['xoffnext'] = $this->request->post['xoffnext'];
                } else if (isset($product_info)) {
                    $this->data['xoffnext'] = $product_info['xoffnext'];
                } else {
                    $this->data['xoffnext'] = '';
                }
                ]]></add>
        </operation>
    </file>

    <file name="admin/model/catalog/product.php">

        <operation>
            <search position="replace"><![CDATA[
            weight = '" . (float)$data['weight']
            ]]></search>
            <add><![CDATA[
            xoffnext = '" . (int)$data['xoffnext'] . "', weight = '" . (float)$data['weight']
            ]]></add>
        </operation>

    </file>


    <file name="admin/view/template/catalog/product_form.tpl">

        <operation>
            <search position="replace" offset="1"><![CDATA[
            <td><input type="text" name="cost" value="<?php echo $cost; ?>" /></td>
            ]]></search>
            <add><![CDATA[
            <td><input type="text" name="cost" value="<?php echo $cost; ?>" /></td>
            </tr>
            <tr>
            <td>X Off Next Purchase:</td>
            <td><input type="text" name="xoffnext" value="<?php echo $xoffnext; ?>" />
            <span class="help">If price is specified, this wll add an image to the listing for X off your next purchase!</span>
            </td>
            </tr>            
            ]]></add>
        </operation>
    </file>

    <file name="catalog/controller/product/product.php">

        <operation info="Add Query to Cart File">
            <search position="after"><![CDATA[
            $this->data['product_id'] = $this->request->get['product_id'];
            ]]></search>
            <add><![CDATA[
            $this->data['xoffnext'] = $product_info['xoffnext'];
            ]]></add>
        </operation>

        <operation info="Add Query to Cart File">
            <search position="after"><![CDATA[
            'image'         => $this->model_tool_image->resize($image, 38, 38),
            ]]></search>
            <add><![CDATA[
            'xoffnext'      => $xoffnext,
            ]]></add>
        </operation>
        
    </file>


    <file path="catalog/controller/product/" name="category.php,search.php,manufacturer.php">

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

    <file path="catalog/view/theme/default/template/product/" name="category.tpl,search.tpl,manufacturer.tpl">

        <operation info="Add Query to Cart File">
            <search position="before"><![CDATA[
            <?php if (!$products[$j]['special']) { ?>
            ]]></search>
            <add><![CDATA[
            <?php if ($products[$j]['xoffnext'] > '0.0000') { ?>
            <a style="color: #900; font-weight: bold;" href="<?php echo $products[$j]['href']; ?>">View Special Offer</a>
            <?php } else { ?>
            ]]></add>
        </operation>

        <operation info="Add Query to Cart File">
            <search position="after"><![CDATA[
            <span style="color: #900; font-weight: bold; text-decoration: line-through;"><?php echo $products[$j]['price']; ?></span> <span style="color: #F00;"><?php echo $products[$j]['special']; ?></span>
            ]]></search>
            <add><![CDATA[
            <?php } ?>
            ]]></add>
        </operation>
        
    </file>

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

        <operation info="Add Query to Cart File">
            <search position="before"><![CDATA[
            <!-- NOPE - NOT WORKING -->
            ]]></search>
            <add><![CDATA[
            <?php if($product_info['xoffnext'] > '0') { ?>
            <style>
            .xoffnext {
                width:425px;
                height:145px;
                color: #000;
                background: #C5FFAC url(https://cdn4.iconfinder.com/data/icons/is_beta_accounting/png/256/money.png) no-repeat;
                border: 1px solid #4C851C;
                background-size: 125px;
                background-position: 340px 45px;
                -webkit-border-radius: 4px;
                -moz-border-radius: 4px;
                border-radius: 4px;
                margin-bottom:10px;
                <?php if($product_info['shipping_by_product'] <= '0.0100' && !in_array($product_id, $exelidarray)){ ?> 
                margin-top: -150px;
                margin-left: 295px;
                <?php  } else if($product_info['shipping_by_product'] <= '0.0100' && in_array($product_id, $exelidarray)){ ?>
                margin-top: -35px;
                margin-left: 295px;
                <?php  } else { ?>
                margin-top: 0px;
                margin-left: 147.5px;
                <?php  }  ?>
            }

            .xoffnext .text {
                padding:10px;
                text-align: center;
            }
            .xoffnext b {
                font-size:9px;    
            }

            .xoffnext .amount {
                font-size:22px;
                margin-bottom:5px;
                display:block;
                
            }
            </style>

            <div class="xoffnext">
                <div class="text">
                    <span class="amount">Purchase this product and receive <?php echo $this->currency->format($this->tax->calculate($product_info['xoffnext'], $result['tax_class_id'], $this->config->get('config_tax'))); ?> off your next purchase*</span>
                    <b>*Discount certificate is good for a <?php echo $this->currency->format($this->tax->calculate($product_info['xoffnext'], $result['tax_class_id'], $this->config->get('config_tax'))); ?> discount against your future purchase of <?php $xoffif = $product_info['xoffnext'] * 10; echo $this->currency->format($this->tax->calculate($xoffif, $result['tax_class_id'], $this->config->get('config_tax'))); ?> or more. Within 72 hours after checkout you will be e-mailed a certificate with a one time use discount voucher which you will be able to use any time within the next 12 months. If you choose to cancel the original transaction, the discount voucher will no longer be valid.</b>
                </div>
            </div>

            <?php } ?>
            ]]></add>
        </operation>
        
    </file>
</modification>