<?xml version="1.0" encoding="utf-8"?>
<modification>
  <name>X-Gift</name>
  <code>xgift</code>
    <version>2.0.4</version>
    <author>OpenCartMart</author>
    <link>http://www.opencartmart.com</link>
    <file path="catalog/controller/checkout/cart.php">
        <operation error="log">
            <search><![CDATA[ $this->cart->getProducts( ]]></search>
            <add position="before"><![CDATA[
                  /* X-gift */
                 $xgift = $this->xgift ? $this->xgift->getActiveGift() : false;
                 if ($xgift) {
                    $this->xgift->clean($xgift['xgift_id']);
                 }
            ]]></add>
        </operation>
         <operation error="log">
            <search><![CDATA[ $this->cart->add( ]]></search>
            <add position="after"><![CDATA[
                  /* X-gift */
                 $xgift = $this->xgift ? $this->xgift->getActiveGift() : false;
                 if ($xgift) {
                    $this->xgift->clean($xgift['xgift_id']);
                 }
            ]]></add>
        </operation>
        <operation error="log">
            <search><![CDATA[ $this->cart->remove( ]]></search>
            <add position="after"><![CDATA[
                  /* X-gift */
                 $xgift = $this->xgift ? $this->xgift->getActiveGift() : false;
                 if ($xgift) {
                    $this->xgift->clean($xgift['xgift_id']);
                 }
            ]]></add>
        </operation>
    </file>
        <file path="system/library/cart/cart.php">
        <operation error="log">
            <ignoreif regex="true"><![CDATA[ /ocmprice/ ]]></ignoreif>
            <search><![CDATA[ $this->weight = $registry->get('weight'); ]]></search>
            <add position="after"><![CDATA[
                  $this->ocmprice = new \Ocmprice($registry);
                  $registry->set('ocmprice', $this->ocmprice);
            ]]></add>
        </operation>
        <operation error="log">
            <ignoreif regex="true"><![CDATA[ /ocmprice->applyCartPrice/ ]]></ignoreif>
            <search regex="true"><![CDATA[ /\$this->data\[\$key\]\s*=\s*array\(|\$product_data\[\]\s*=\s*array\(/ ]]></search>
            <add position="replace"><![CDATA[
                if (property_exists($this, 'ocmprice')) {
                    if (VERSION < '2.1.0.0') {
                        $product['quantity'] = $quantity;
                    }
                    $_ocmprice_data = array(
                        'price'        => &$price,
                        'option_price' => &$option_price,
                        'option_data'  => &$option_data,
                        'product'      => &$product_query->row,
                        'quantity'     => $discount_quantity,
                        'carts'        => VERSION >= '2.1.0.0' ? $cart_query->rows : $this->session->data['cart'],
                        'cart'         => VERSION >= '2.1.0.0' ? $cart : $product,
                        'special'      => $product_special_query->row ? $product_special_query->row['price'] : 0,
                        'discount'     => $product_discount_query->row ? $product_discount_query->row['price'] : 0
                    );
                    $this->ocmprice->applyCartPrice($_ocmprice_data);
                    // recheck stock status
                    if (VERSION >= '2.1.0.0' && (int)$product_query->row['quantity'] < $cart['quantity']) {
                        $stock = false;
                    }
                }
                $0
            ]]></add>
        </operation>
        <operation error="log">
            <ignoreif regex="true"><![CDATA[ /ocmprice->onCartOperation/ ]]></ignoreif>
            <search regex="true"><![CDATA[ /public\s+function\s+(update|remove)\(.*?\)\s+{/ ]]></search>
            <add position="after"><![CDATA[
                 $0
                 if (property_exists($this, 'ocmprice')) {
                     $_ocmprice = $this->ocmprice->onCartOperation((VERSION >= '2.1.0.0' ? $cart_id : $key), __FUNCTION__);
                     //d_qc use this update function to remove cart product, sigh! so patch
                     if (isset($quantity) && !$quantity && isset($_ocmprice['stop'])) {
                        unset($_ocmprice['stop']);
                     }
                     if ($_ocmprice && isset($_ocmprice['stop'])) {
                        return false;
                     }
                 }
            ]]></add>
        </operation>
        <operation error="log">
            <ignoreif regex="true"><![CDATA[ /ocmprice->onCartProducts/ ]]></ignoreif>
            <search regex="true"><![CDATA[ /public\s+function\s+getProducts\(.*?\)\s+{/ ]]></search>
            <add position="after"><![CDATA[
                 $0
                 if (property_exists($this, 'ocmprice')) {
                     $this->ocmprice->onCartProducts();
                 }
            ]]></add>
        </operation>
    </file>
    <file path="system/library/cart/cart.php">
    <operation error="log">
        <ignoreif regex="true"><![CDATA[ /ocm_special/ ]]></ignoreif>
        <search><![CDATA[ => ($price + $option_price), ]]></search>
        <add position="before"><![CDATA[
              'ocm_special'      => $price != $product_query->row['price'],
        ]]></add>
    </operation>
</file>
</modification>