<?xml version="1.0" encoding="utf-8"?>
<modification>
    <name>X-Bundle</name>
    <code>xbundle</code>
    <version>1.0.3</version>
    <author>OpenCartMart</author>
    <link>https://opencartmart.com</link>
    <file path="admin/controller/catalog/product.php">
        <operation error="log">
            <search><![CDATA[ $this->response->setOutput($this->load->view('catalog/product_form ]]></search>
            <add position="before"><![CDATA[
                  /* xbundle */
                  $data['xbundle_tab'] = $this->load->controller('extension/module/xbundle/getBundleTab');
            ]]></add>
        </operation>
    </file>
    <file path="admin/view/template/catalog/product_form.twig">
        <operation error="log">
            <search><![CDATA[ <li><a href="#tab-design" data-toggle="tab">{{ tab_design }}</a></li> ]]></search>
            <add position="after"><![CDATA[
                 <li><a href="#tab-bundle" data-toggle="tab">Product Bundle</a></li>
            ]]></add>
        </operation>
        <operation error="log">
            <search><![CDATA[ <div class="tab-pane" id="tab-design"> ]]></search>
            <add position="before"><![CDATA[
                 {{ xbundle_tab }}
            ]]></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')) {
                    $___price = $price; // keep a backup of old price. It may be required for some cases.
                    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>
</modification>