<?xml version="1.0" encoding="UTF-8"?>
<modification>
        <name>Marketplace 1</name>
        <version>2.0.0</version>
        <code>Webkul Marketplace 1</code>
        <author>Webkul</author>
        <link>http://webkul.com</link>

        <file path="admin/controller/common/column_left.php">
                <operation>
                        <search><![CDATA[
              // Catalog
                        ]]></search>
                        <add position="before"><![CDATA[
        // marketplace code starts here

            if ($this->config->get('marketplace_status')) {

                $marketplace = array();

                if ($this->user->hasPermission('access', 'customerpartner/partner')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_partner'),
                        'href'     => $this->url->link('customerpartner/partner', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/commission')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_commission'),
                        'href'     => $this->url->link('customerpartner/commission', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/product')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_product'),
                        'href'     => $this->url->link('customerpartner/product', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/category')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_categories'),
                        'href'     => $this->url->link('customerpartner/category', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/categorymapping')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_categories_mapping'),
                        'href'     => $this->url->link('customerpartner/categorymapping', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/order')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_order'),
                        'href'     => $this->url->link('customerpartner/order', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/income')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_income'),
                        'href'     => $this->url->link('customerpartner/income', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/transaction')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_transaction'),
                        'href'     => $this->url->link('customerpartner/transaction', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/shipping')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_shipping'),
                        'href'     => $this->url->link('customerpartner/shipping', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/mails')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_mail'),
                        'href'     => $this->url->link('customerpartner/mails', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/review')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_seller_review'),
                        'href'     => $this->url->link('customerpartner/review', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($this->user->hasPermission('access', 'customerpartner/reviewfield')) {
    $marketplace[] = array(
        'name'     => $this->language->get('text_review_field'),
        'href'     => $this->url->link('customerpartner/reviewfield', 'token=' . $this->session->data['token'], true),
        'children' => array()
    );
}

if ($this->user->hasPermission('access', 'customerpartner/notification')) {
$marketplace[] = array(
'name'     => $this->language->get('text_notifications'),
'href'     => $this->url->link('customerpartner/notification', 'token=' . $this->session->data['token'], true),
'children' => array()
);
}

if ($this->user->hasPermission('access', 'wkcustomfield/wkcustomfield')) {
                    $marketplace[] = array(
                        'name'     => $this->language->get('text_custom_field'),
                        'href'     => $this->url->link('wkcustomfield/wkcustomfield', 'token=' . $this->session->data['token'], true),
                        'children' => array()
                    );
                }

                if ($marketplace) {
                    $data['menus'][] = array(
                        'id'       => 'menu-marketplace',
                        'icon'     => 'fa-users',
                        'name'     => $this->language->get('text_marketplace'),
                        'href'     => '',
                        'children' => $marketplace
                    );
                }

            }

            // marketplace code ends here
                        ]]></add>
                </operation>
        </file>

        <file path="admin/language/*/common/column_left.php">
                <operation>
                        <search><![CDATA[
                $_['text_other_status']
                        ]]></search>
                        <add position="after"><![CDATA[
                // Marketplace code starts

                $_['text_marketplace']               = 'Marketplace';
                $_['text_partner']                   = 'Sellers';
                $_['text_commission']                = 'Commission';
                $_['text_product']                   = 'Products';
                $_['text_categories']                = 'Categories';
                $_['text_categories_mapping']        = 'Category Attribute Mapping';
                $_['text_order']                     = 'Orders';
                $_['text_income']                    = 'Income';
                $_['text_transaction']               = 'Transaction';
                $_['text_shipping']                  = 'Shipping';
                $_['text_mail']                      = 'Mail';
                $_['text_seller_review']                    = 'Seller Reviews';
$_['text_review_field']              = 'Seller Review Fields';
$_['text_notifications']              = 'Notifications';
                $_['text_custom_field']              = 'Custom Fields';

                // Marketplace code ends
                        ]]></add>
                </operation>
        </file>



        <!-- delete product from seller table if admin delete product -->
        <file path="admin/model/catalog/product.php">
                <operation>
                        <search><![CDATA[
    $this->db->query("DELETE FROM " . DB_PREFIX . "review WHERE product_id = '" . (int)$product_id . "'");
                        ]]></search>
                        <add position="after"><![CDATA[
    $this->db->query("DELETE FROM " . DB_PREFIX . "customerpartner_to_product WHERE product_id = '" . (int)$product_id . "'");
    //commented because it's also important for order
    //$this->db->query("DELETE FROM " . DB_PREFIX . "customerpartner_sold_tracking WHERE product_id = '" . (int)$product_id . "'");
                       ]]></add>
                </operation>
                <operation>
                        <search><![CDATA[
    public function editProduct($product_id, $data) {
                        ]]></search>
                        <add position="after"><![CDATA[
        /**
         * Marketplace
         */
        if ($this->config->get('marketplace_status')) {

            $checkSellerProduct = $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "customerpartner_to_product WHERE product_id = '" . (int)$product_id."' ORDER BY id ASC")->row;

            if ($checkSellerProduct) {

                $updatePrice = $this->currency->convert($data['price'],$this->config->get('config_currency'),$checkSellerProduct['currency_code']);

                $this->db->query("UPDATE " . DB_PREFIX . "customerpartner_to_product SET price = '".(float)$data['price']."',seller_price = '".(float)$updatePrice."'  WHERE product_id = '".$product_id."' ORDER BY id ASC");
            }
        }

        /**
         * Marketplace
         */
                       ]]></add>
                </operation>
        </file>

    <!--  display seller name with product in order info and after edit   -->
        <file path="admin/controller/sale/order.php">
            <operation>
                    <search><![CDATA[
                $data['products'][] = array(
                    ]]></search>
                    <add position="before"><![CDATA[

    $seller_details = $this->db->query("SELECT c.customer_id,CONCAT(c.firstname,' ',c.lastname) name,c.email FROM ".DB_PREFIX."customerpartner_to_product c2p LEFT JOIN ".DB_PREFIX."customer c ON (c2p.customer_id = c.customer_id) WHERE c2p.product_id = '".(int)$product['product_id']."'")->row;

    if($seller_details AND isset($seller_details['name']) AND $seller_details['name'])
      $product['name'] = $product['name'].'</a> by Seller <a href="'.$this->url->link('customerpartner/partner', 'token=' . $this->session->data['token'] . '&view_all=1&filter_email=' . $seller_details['email'], true).'"><b>'.$seller_details['name'].'</b></a>';

                      ]]></add>
            </operation>

            <operation>
                    <search><![CDATA[
                $data['order_products'][] = array(
                    ]]></search>
                    <add position="before"><![CDATA[

    $seller_details = $this->db->query("SELECT c.customer_id,CONCAT(c.firstname,' ',c.lastname) name,c.email FROM ".DB_PREFIX."customerpartner_to_product c2p LEFT JOIN ".DB_PREFIX."customer c ON (c2p.customer_id = c.customer_id) WHERE c2p.product_id = '".(int)$product['product_id']."'")->row;

    if($seller_details AND isset($seller_details['name']) AND $seller_details['name'])
      $product['name'] = $product['name'].' by Seller <b>'.$seller_details['name'].'</b>';

                      ]]></add>
            </operation>

        </file>

    <!-- Sell Link in header -->
    <file path="catalog/controller/common/header.php">
            <operation>
                    <search><![CDATA[
        $data['checkout'] = $this->url->link('checkout/checkout', '', true);
                    ]]></search>
                    <add position="after"><![CDATA[
        $data['notification'] = '';
$data['menusell'] = $this->url->link('customerpartner/sell', '', true);
        $this->language->load('extension/module/marketplace');
        $data['marketplace_status'] = $this->config->get('marketplace_status');
        $data['text_sell_header'] = $this->language->get('text_sell_header');
        $data['text_my_profile'] = $this->language->get('text_my_profile');
        $data['text_addproduct'] = $this->language->get('text_addproduct');
        $data['text_wkshipping'] = $this->language->get('text_wkshipping');
        $data['text_productlist'] = $this->language->get('text_productlist');
        $data['text_dashboard'] = $this->language->get('text_dashboard');
        $data['text_orderhistory'] = $this->language->get('text_orderhistory');
        $data['text_becomePartner'] = $this->language->get('text_becomePartner');
        $data['text_download'] = $this->language->get('text_download');
        $data['text_transaction'] = $this->language->get('text_transaction');
        $data['marketplace_allowed_account_menu'] = $this->config->get('marketplace_allowed_account_menu');
        $data['mp_addproduct'] = $this->url->link('account/customerpartner/addproduct', '', true);
        $data['mp_productlist'] = $this->url->link('account/customerpartner/productlist', '', true);
        $data['mp_dashboard'] = $this->url->link('account/customerpartner/dashboard', '', true);
        $data['mp_add_shipping_mod'] = $this->url->link('account/customerpartner/add_shipping_mod','', true);
        $data['mp_orderhistory'] = $this->url->link('account/customerpartner/orderlist','', true);
        $data['mp_download'] = $this->url->link('account/customerpartner/download','', true);
        $data['mp_profile'] = $this->url->link('account/customerpartner/profile','',true);
        $data['mp_want_partner'] = $this->url->link('account/customerpartner/become_partner','',true);
        $data['mp_transaction'] = $this->url->link('account/customerpartner/transaction','',true);
        $this->load->model('account/customerpartner');
        if($this->config->get('marketplace_status')){
            $data['chkIsPartner'] = $this->model_account_customerpartner->chkIsPartner();
            $data['marketplace_seller_mode'] = isset($this->session->data['marketplace_seller_mode']) ? $this->session->data['marketplace_seller_mode'] : 1;
if ($data['chkIsPartner'] && $data['marketplace_seller_mode']) {
  $data['notification'] = $this->load->controller('account/customerpartner/notification/notifications');
}
        }
                    ]]></add>
            </operation>
    </file>

    <file path="catalog/view/theme/journal2/template/common/header.tpl">
            <operation>
                    <search><![CDATA[
        <li class="dropdown"><a href="<?php echo $account; ?>"
                    ]]></search>
                    <add position="before"><![CDATA[
    <?php if(isset($marketplace_status) && $marketplace_status){ ?>
        <?php if ($logged AND $chkIsPartner && isset($marketplace_seller_mode) && $marketplace_seller_mode) { ?>
  <li id="wk-notify"><a id="notification" data-toggle="modal" data-target="#myModal-notification"></a></li>
<?php } ?>
        <li class="dropdown"><a href="<?php echo $menusell; ?>" title="<?php echo $menusell; ?>" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-users"></i> <span class="hidden-xs hidden-sm hidden-md"><?php echo $text_sell_header; ?></span> <span class="caret"></span></a>
            <ul class="dropdown-menu dropdown-menu-right">
              <?php if ($logged AND $chkIsPartner && isset($marketplace_seller_mode) && $marketplace_seller_mode) { ?>
                <?php if(isset($marketplace_allowed_account_menu) && $marketplace_allowed_account_menu && in_array('profile',$marketplace_allowed_account_menu)) { ?>
                    <li><a href="<?php echo $mp_profile; ?>"><?php echo $text_my_profile; ?></a></li>
                <?php } ?>
                <?php if(isset($marketplace_allowed_account_menu) && $marketplace_allowed_account_menu && in_array('dashboard',$marketplace_allowed_account_menu)) { ?>
                    <li><a href="<?php echo $mp_dashboard; ?>"><?php echo $text_dashboard; ?></a></li>
                <?php } ?>
                <?php if(isset($marketplace_allowed_account_menu) && $marketplace_allowed_account_menu && in_array('orderhistory',$marketplace_allowed_account_menu)) { ?>
                    <li><a href="<?php echo $mp_orderhistory; ?>"><?php echo $text_orderhistory; ?></a></li>
                <?php } ?>
                <?php if(isset($marketplace_allowed_account_menu) && $marketplace_allowed_account_menu && in_array('transaction',$marketplace_allowed_account_menu)) { ?>
                    <li><a href="<?php echo $mp_transaction; ?>"><?php echo $text_transaction; ?></a></li>
                <?php } ?>
                <?php if(isset($marketplace_allowed_account_menu) && $marketplace_allowed_account_menu && in_array('productlist',$marketplace_allowed_account_menu)) { ?>
                    <li><a href="<?php echo $mp_productlist; ?>"><?php echo $text_productlist; ?></a></li>
                <?php } ?>
                <?php if(isset($marketplace_allowed_account_menu) && $marketplace_allowed_account_menu && in_array('download',$marketplace_allowed_account_menu)) { ?>
                    <li><a href="<?php echo $mp_download; ?>"><?php echo $text_download; ?></a></li>
                <?php } ?>
                <?php if(isset($marketplace_allowed_account_menu) && $marketplace_allowed_account_menu && in_array('manageshipping',$marketplace_allowed_account_menu)) { ?>
                    <li><a href="<?php echo $mp_add_shipping_mod; ?>"><?php echo $text_wkshipping; ?></a></li>
                <?php } ?>
                <li role="presentation" class="divider"></li>
              <?php } ?>
              <?php //}else{ ?>
                <li><a href="<?php echo $menusell; ?>"><?php echo $text_sell_header; ?></a></li>
                <!--<li><a href="<?php echo $mp_want_partner; ?>"><?php echo $text_becomePartner; ?></a></li>-->
            </ul>
        </li>
    <?php } ?>
                         ]]></add>
            </operation>
    </file>

    <file path="catalog/controller/account/register.php">
                <operation>
                        <search><![CDATA[
        $data['column_left'] = $this->load->controller('common/column_left');
                        ]]></search>
                        <add position="before"><![CDATA[
        $data['marketplace_becomepartnerregistration'] = false;
        $data['marketplace_status'] = false;
        if($this->config->get('marketplace_status') && $this->config->get('marketplace_becomepartnerregistration')){
            $data['marketplace_becomepartnerregistration'] = $this->config->get('marketplace_becomepartnerregistration');
            $data['marketplace_status'] = $this->config->get('marketplace_status');
            $this->language->load('account/customerpartner/become_partner');

            $data['text_register_becomePartner'] = $this->language->get('text_register_becomePartner');
            $data['text_register_douwant'] = $this->language->get('text_register_douwant');
            $data['text_shop_name'] = $this->language->get('text_shop_name');
            $data['text_avaiable'] = $this->language->get('text_avaiable');
            $data['text_no_avaiable'] = $this->language->get('text_no_avaiable');

            if (isset($this->request->post['shoppartner'])) {
                $data['shoppartner'] = $this->request->post['shoppartner'];
            } else {
                $data['shoppartner'] = '';
            }

            if (isset($this->request->post['tobecomepartner'])) {
                $data['tobecomepartner'] = $this->request->post['tobecomepartner'];
            } else {
                $data['tobecomepartner'] = '';
            }

            if (isset($this->error['errshoppartner'])) {
                $data['error_shoppartner'] = $this->error['errshoppartner'];
            } else {
                $data['error_shoppartner'] = '';
            }

        }

                        ]]></add>
                </operation>

                <operation>
                        <search><![CDATA[
        function validate() {
                        ]]></search>
                        <add position="after"><![CDATA[

        if($this->config->get('marketplace_becomepartnerregistration') AND isset($this->request->post['tobecomepartner'])){

            $this->language->load('account/customerpartner/become_partner');

            if(utf8_strlen($this->request->post['shoppartner'])<=3 && $this->request->post['tobecomepartner']==1){
                $this->error['errshoppartner'] = $this->language->get('error_validshop');
            }else if(utf8_strlen($this->request->post['shoppartner']) >1 && $this->request->post['tobecomepartner']==1){
                $this->load->model('customerpartner/master');
                if($this->model_customerpartner_master->getShopData($this->request->post['shoppartner'])){
                  $this->error['errshoppartner'] = $this->language->get('error_noshop');
                }
            }

            $this->language->load('account/register');
        }
                        ]]></add>
                </operation>

                <operation>
                        <search><![CDATA[
        unset($this->session->data['guest']);
                        ]]></search>
                        <add position="before"><![CDATA[
            if($this->config->get('marketplace_becomepartnerregistration')){
                if ($this->request->post['tobecomepartner']=='1' && $this->request->post['shoppartner']) {
                    $this->load->model('account/customerpartner');
                    $this->model_account_customerpartner->becomePartner($this->request->post['shoppartner'],$this->request->post['country_id'],$customer_id);
                }
            }

                       ]]></add>
                </operation>

        </file>

        <file path="catalog/view/theme/default/template/account/register.tpl">
                <operation>
                        <search><![CDATA[
                    <?php if ($text_agree) { ?>
                        ]]></search>
                        <add position="before"><![CDATA[
    <?php if($marketplace_status && $marketplace_becomepartnerregistration){ ?>

        <fieldset>
          <legend><?php echo $text_register_becomePartner; ?></legend>
          <div class="form-group">
            <label class="col-sm-2 control-label"><?php echo $text_register_douwant; ?></label>
            <div class="col-sm-10">
              <?php if ($tobecomepartner) { ?>
              <label class="radio-inline">
                <input type="radio" name="tobecomepartner" value="1" checked="checked" />
                <?php echo $text_yes; ?></label>
              <label class="radio-inline">
                <input type="radio" name="tobecomepartner" value="0" />
                <?php echo $text_no; ?></label>
              <?php } else { ?>
              <label class="radio-inline">
                <input type="radio" name="tobecomepartner" value="1" />
                <?php echo $text_yes; ?></label>
              <label class="radio-inline">
                <input type="radio" name="tobecomepartner" value="0" checked="checked" />
                <?php echo $text_no; ?></label>
              <?php } ?>
            </div>
          </div>

          <div class="form-group required hide" id="fg-shoppartner">
            <label class="col-sm-2 control-label" for="input-shop"><?php echo $text_shop_name; ?></label>
            <div class="col-sm-10">
              <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-search"></i></span>
                <input type="text" name="shoppartner" value="<?php echo $shoppartner; ?>" placeholder="<?php echo $text_shop_name; ?>" id="input-shop" class="form-control" />
              </div>
              <?php if ($error_shoppartner) { ?>
              <div class="text-danger"><?php echo $error_shoppartner; ?></div>
              <?php } ?>
            </div>
          </div>

        </fieldset>

        <script>

          $('input[name=\'tobecomepartner\']').on('change', function() {
            if ($(this).val() == 1) {
              $('#fg-shoppartner').removeClass('hide');
            } else {
              $('#fg-shoppartner').addClass('hide');
            }
          });

            $( "#input-shop" ).change(function() {
              thisshop = this;
              shop = $(thisshop).val();

              if(shop){

                jQuery(thisshop).prev().html('<i class="fa fa-spinner fa-spin"></i>');

                $.ajax({
                       type: 'POST',
                       data: ({shop: shop}),
                       dataType: 'json',
                       url: 'index.php?route=customerpartner/sell/wkmpregistation',
                       success: function(data){

                          if(data['success']){
                            jQuery(thisshop).prev().html('<span data-toggle="tooltip" class="text-success" title="<?php echo $text_avaiable; ?>"><i class="fa fa-thumbs-o-up"></i></span>');
                          }else if(data['error']){
                            jQuery(thisshop).prev().html('<span data-toggle="tooltip" class="text-danger" title="<?php echo $text_no_avaiable; ?>"><i class="fa fa-thumbs-o-down"></i></span>');
                          }

                        }
                    });
              }
            });
        </script>
    <?php } ?>
                              ]]></add>
                </operation>
        </file>

<!-- code addition for journal2 theme -->
        <file path="catalog/view/theme/journal2/template/account/register.tpl">
                <operation>
                        <search><![CDATA[
                    <?php if ($text_agree) { ?>
                        ]]></search>
                        <add position="before"><![CDATA[
    <?php if($marketplace_status && $marketplace_becomepartnerregistration){ ?>

        <fieldset>
          <h2 class="secondary-title"><?php echo $text_register_becomePartner; ?></h2>
          <div class="form-group">
            <label class="col-sm-2 control-label"><?php echo $text_register_douwant; ?></label>
            <div class="col-sm-10">
              <?php if ($tobecomepartner) { ?>
              <label class="radio-inline">
                <input type="radio" name="tobecomepartner" value="1" checked="checked" />
                <?php echo $text_yes; ?></label>
              <label class="radio-inline">
                <input type="radio" name="tobecomepartner" value="0" />
                <?php echo $text_no; ?></label>
              <?php } else { ?>
              <label class="radio-inline">
                <input type="radio" name="tobecomepartner" value="1" />
                <?php echo $text_yes; ?></label>
              <label class="radio-inline">
                <input type="radio" name="tobecomepartner" value="0" checked="checked" />
                <?php echo $text_no; ?></label>
              <?php } ?>
            </div>
          </div>

          <div class="form-group required hide" id="fg-shoppartner">
            <label class="col-sm-2 control-label" for="input-shop"><?php echo $text_shop_name; ?></label>
            <div class="col-sm-10">
              <div class="input-group">
                <span class="input-group-addon"><i class="fa fa-search button"></i></span>
                <input type="text" name="shoppartner" value="<?php echo $shoppartner; ?>" placeholder="<?php echo $text_shop_name; ?>" id="input-shop" class="form-control" style="width:auto;"  />
              </div>
              <?php if ($error_shoppartner) { ?>
              <div class="text-danger"><?php echo $error_shoppartner; ?></div>
              <?php } ?>
            </div>
          </div>

        </fieldset>

        <script>

          $('input[name=\'tobecomepartner\']').on('change', function() {
            if ($(this).val() == 1) {
              $('#fg-shoppartner').removeClass('hide');
            } else {
              $('#fg-shoppartner').addClass('hide');
            }
          });

            $( "#input-shop" ).change(function() {
              thisshop = this;
              shop = $(thisshop).val();

              if(shop){

                jQuery(thisshop).prev().html('<i class="fa fa-spinner fa-spin"></i>');

                $.ajax({
                       type: 'POST',
                       data: ({shop: shop}),
                       dataType: 'json',
                       url: 'index.php?route=customerpartner/sell/wkmpregistation',
                       success: function(data){

                          if(data['success']){
                            jQuery(thisshop).prev().html('<span data-toggle="tooltip" class="text-success" title="<?php echo $text_avaiable; ?>"><i class="fa fa-thumbs-o-up"></i></span>');
                          }else if(data['error']){
                            jQuery(thisshop).prev().html('<span data-toggle="tooltip" class="text-danger" title="<?php echo $text_no_avaiable; ?>"><i class="fa fa-thumbs-o-down"></i></span>');
                          }

                        }
                    });
              }
            });
        </script>
    <?php } ?>
                              ]]></add>
                </operation>
        </file>

        <!-- code for unset session variable on logout for pop-up modal with information -->
        <file path="system/library/cart/customer.php">
            <operation>
                <search><![CDATA[
                    unset($this->session->data['customer_id']);
                ]]></search>
                <add position="after"><![CDATA[
                    unset($this->session->data['openModal']);
                ]]></add>
            </operation>
        </file>

        <!-- send mail to seller after product sold -->
        <file path="catalog/model/checkout/order.php">

          <operation>
            <search><![CDATA[
        // Admin Alert Mail
            ]]></search>
            <add position="before"><![CDATA[
                //for Marketplace management
                if ($this->config->get('marketplace_status')){
                   $this->load->model('account/customerpartnerorder');
                   $this->model_account_customerpartnerorder->customerpartner($order_info,$order_status, $comment);
                }
            ]]></add>
           </operation>

           <operation>
            <search><![CDATA[
            $customer_info = $this->model_account_customer->getCustomer($order_info['customer_id']);
            ]]></search>
            <add position="before"><![CDATA[
            $toAdmin = false;
            if(isset($comment) && $comment) {
                $get_comment = explode('___',$comment);
                if($get_comment[0] == 'wk_admin_comment' ) {
                    $comment = ($get_comment[1]);
                    $toAdmin = true;
                    $this->config->set('config_email',$this->customer->getEmail());
                    if($this->config->get('marketplaceadminmail')) {
                        $order_info['email'] = $this->config->get('marketplace_adminmail');
                    } else {
                        $order_info['email'] = $this->config->get('config_email');
                    }
                }
            }
            ]]></add>
           </operation>

           <operation>
            <search><![CDATA[
            $message .= $language->get('text_update_order_status') . "\n\n";
            ]]></search>
            <add position="replace"><![CDATA[
                    if(isset($toAdmin) && $toAdmin) {
                        $message .= $language->get('text_update_order_status_admin') . "\n\n";
                    } else {
                        $message .= $language->get('text_update_order_status') . "\n\n";
                    }
            ]]></add>
           </operation>
            <operation>
            <search><![CDATA[
            $message .= $language->get('text_update_comment') . "\n\n";
            ]]></search>
            <add position="replace"><![CDATA[
                    if(isset($toAdmin) && $toAdmin) {
                        $message .= $language->get('text_update_comment_admin') . "\n\n";
                    } else {
                        $message .= $language->get('text_update_comment') . "\n\n";
                    }
            ]]></add>
           </operation>
            <operation>
            <search><![CDATA[
            $message .= $language->get('text_update_link') . "\n";
            ]]></search>
            <add position="before"><![CDATA[
                    if(isset($toAdmin) && !$toAdmin) {
            ]]></add>
           </operation>
           <operation>
            <search><![CDATA[
            $message .= $language->get('text_update_link') . "\n";
            ]]></search>
            <add position="after" offset="1"><![CDATA[
                    }
            ]]></add>
           </operation>
            <operation>
                <search><![CDATA[
                    $this->db->query("DELETE FROM `" . DB_PREFIX . "order`
                ]]></search>
            <add position="before"><![CDATA[
              $str = '%order_id_:' . $order_id . '_';

              $this->db->query("DELETE FROM ".DB_PREFIX."customer_activity WHERE data LIKE '" . $str . "'");

              if($this->config->get('marketplace_status')) {

              $transaction = $this->db->query("SELECT * FROM " . DB_PREFIX . "customerpartner_to_transaction")->rows;

              if ($transaction) {
                foreach ($transaction as $key => $value) {

                  $order_ids = explode(',',$value['order_id']);

                  if ($order_ids && in_array($order_id,$order_ids)) {

                    $paid_amount = $this->db->query("SELECT SUM(customer) AS paid_amount FROM " . DB_PREFIX . "customerpartner_to_order WHERE order_id = " . (int)$order_id . " AND customer_id = ". $value['customer_id'])->row;

                    if (isset($paid_amount['paid_amount']) && $paid_amount['paid_amount']) {
                      if ($paid_amount['paid_amount'] == $value['amount']) {
                        $this->db->query("DELETE FROM ".DB_PREFIX."customerpartner_to_transaction WHERE id = '".(int)$value['id']."' ");
                      } else {
                        $amount = $value['amount'] - $paid_amount['paid_amount'];

                        $text = substr($value['text'],0,1) . $amount;

                        $this->db->query("UPDATE ".DB_PREFIX."customerpartner_to_transaction SET amount = " . $amount . ", text = '" . $text . "' WHERE id = '".(int)$value['id']."' ");
                      }
                    }
                  }
                }
              }

                $this->db->query("DELETE FROM ".DB_PREFIX."mp_customer_activity WHERE data LIKE '" . $str . "'");

                $this->db->query("DELETE FROM ".DB_PREFIX."customerpartner_to_order WHERE order_id = '".(int)$order_id."' ");
             $this->db->query("DELETE FROM ".DB_PREFIX."customerpartner_to_order_status WHERE order_id = '".(int)$order_id."' ");
             $this->db->query("DELETE FROM ".DB_PREFIX."customerpartner_sold_tracking WHERE order_id = '".(int)$order_id."' ");
        }
            ]]></add>
            </operation>

        </file>

        <file path="catalog/language/*/mail/order.php">
            <operation>
                <search><![CDATA[
                $_['text_update_footer']        = 'Please reply to this email if you have any questions.';
                ]]></search>
                <add position="after"><![CDATA[
$_['text_update_order_status_admin']  = 'Order has been updated to the following status:';
$_['text_update_comment_admin']       = 'The comments for above order are:';
                ]]></add>
            </operation>
        </file>

        <!-- code for custom field -->
        <file path="admin/view/template/catalog/product_form.tpl">
                <operation>
                        <search><![CDATA[
                        <li><a href="#tab-design" data-toggle="tab"><?php echo $tab_design; ?></a></li>
                        ]]></search>
                        <add position="before"><![CDATA[
                            <!-- Marketplace customfield -->
                            <li><a href="#tab-custom-field" data-toggle="tab"><?php echo "Custom field"; ?></a></li>
                            <!-- Marketplace customfield -->
                              ]]></add>
                </operation>
                <operation>
                        <search><![CDATA[
                        <div class="tab-pane" id="tab-design">
                        ]]></search>
                        <add position="before"><![CDATA[
            <!--Marketplace Customfield -->
            <div class="tab-pane" id="tab-custom-field">
              <div class="row">
                <div class="col-sm-3">
                  <ul class="nav nav-pills nav-stacked" id="vtab-option">
                      <?php  $tabCount = 0; $wkcustom_option_row = 0;?>
                        <?php if(!empty($wkPreCustomFields)) { ?>
                          <?php foreach($wkPreCustomFields as $tabs) { ?>
                            <li>
                              <a href="#wktab-option-<?php echo $tabCount; ?>" data-toggle="tab" id="wkoption-<?php echo $tabCount; ?>" field-id = "wkoption-<?php echo $tabs['fieldId'];?>"><i class="fa fa-minus-circle" onclick="$('#wkoption-<?php echo $tabCount; ?>').remove(); $('#wktab-option-<?php echo $tabCount; ?>').remove(); $('#vtab-option li a:first').trigger('click'); return false;"></i><?php echo $tabs["fieldName"]; ?></a>
                            </li>
                          <?php $tabCount++; ?>
                        <?php } ?>
                      <?php } ?>
                      <li id="optionSelector">
                        <select name="wkcustomfield" class="form-control">
                          <?php if(!empty($wkcustomFields)){ ?>
                            <option value=""></option>
                              <?php  foreach($wkcustomFields as $field) { ?>
                                <option value="<?php echo $field['id']; ?>" data-type = "<?php echo $field['fieldType']; ?>" data-name="<?php echo $field['fieldName']; ?>" data-des="<?php echo $field['fieldDescription']; ?>" title="<?php echo $field['fieldDescription']; ?>" data-isRequired = "<?php echo $field['isRequired']; ?>">
                                  <?php echo $field['fieldName']; ?>
                                </option>
                              <?php
                              }
                            }
                          ?>
                        </select>
                      </li>
                  </ul>
                </div>

                <div class="col-sm-9">
                  <div class="tab-content" id="wk_customfieldcontent">
                  <?php  $tabCount = 0; $wkcustom_option_row = 0;
                  if(!empty($wkPreCustomFields)) {
                    foreach($wkPreCustomFields as $tabs) { ?>
                      <div id="wktab-option-<?php echo $tabCount; ?>" class="tab-pane">
                        <div class="alert alert-info">
                          <i class="fa fa-info-circle"></i>
                          <?php  echo $tabs['fieldDes']; ?>
                        </div>
                        <?php if(isset($error) && $error == $tabs['fieldId']) { ?>
                            <div class="alert alert-danger">
                              <i class="fa fa-exclamation-circle"></i>
                              <?php echo $error_warning_mandetory; ?>
                            </div>
                        <?php } ?>
                        <input type="hidden" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_name]" value="<?php echo $tabs['fieldName']; ?>">
                        <input type="hidden" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_type]" value="<?php echo $tabs['fieldType']; ?>">
                        <input type="hidden" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_id]" value="<?php echo $tabs['fieldId']; ?>">
                        <input type="hidden" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_des]" value="<?php echo $tabs['fieldDes']; ?>">
                        <input type="hidden" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_is_required]" value="<?php echo $tabs['isRequired']; ?>">

                            <?php if($tabs['fieldType'] == 'select') { ?>
                              <div class="form-group <?php if($tabs['isRequired'] == 'yes') echo 'required'; ?>">
                                <label class="col-sm-3 control-label">Select option:</label>
                                <div class="col-sm-9">
                                  <select class="form-control" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_value][]" >
                                    <?php  foreach($tabs['preFieldOptions'] as $options) { ?>
                                      <option value="<?php echo $options['optionId']; ?>" <?php if(!empty($tabs['fieldOptions'])) { foreach($tabs['fieldOptions'] as $option) { if($option['optionId'] == $options['optionId']) echo "selected"; } } ?> >
                                        <?php echo $options['optionValue']; ?>
                                      </option>
                                    <?php
                                    }  ?>
                                  </select>
                                </div>
                               </div>
                              <?php

                              }else if($tabs['fieldType'] == 'checkbox' || $tabs['fieldType'] == 'radio' ) { ?>
                                <div class="form-group  <?php if($tabs['isRequired'] == 'yes') echo 'required'; ?>">
                                <label class="control-label col-sm-3">Select option:</label>
                                <div class="col-sm-9">
                              <?php  foreach($tabs['preFieldOptions'] as $options) { ?>

                                  <div class="radio checkbox">
                                    <label for="<?php echo $wkcustom_option_row.$options['optionId']; ?>">
                                      <input type='<?php echo $tabs['fieldType']; ?>' id="<?php echo $wkcustom_option_row.$options['optionId']; ?>" value="<?php echo $options['optionId']; ?>" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_value][]" <?php if(!empty($tabs['fieldOptions'])) { foreach($tabs['fieldOptions'] as $option) { if($option['optionId'] == $options['optionId']) echo "checked"; } } ?> />
                                      <?php echo $options['optionValue']; ?>
                                    </label>
                                  </div>

                              <?php }  ?>
                               </div>
                              </div>
                              <?php }else if($tabs['fieldType'] == 'text') { ?>
                                <div class="form-group <?php if($tabs['isRequired'] == 'yes') echo 'required'; ?>">
                                  <label class="col-sm-3 control-label">Enter Text:</label>
                                  <div class="col-sm-9">
                                    <input class="form-control" type="text" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_value][]" value="<?php if(isset($tabs['fieldOptions']['option_id'])) echo $tabs['fieldOptions']['option_id']; ?>" />
                                  </div>
                                </div>
                                <?php
                                }else if($tabs['fieldType'] == 'textarea') { ?>
                                  <div class="form-group <?php if($tabs['isRequired'] == 'yes') echo 'required'; ?>">
                                    <label class="col-sm-3 control-label">Enter Text:</label>
                                    <div class="col-sm-9">
                                      <textarea class="form-control" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_value][]" rows="7" >
                                      <?php if(isset($tabs['fieldOptions']['option_id'])) echo $tabs['fieldOptions']['option_id']; ?>
                                    </textarea>
                                    </div>
                                  </div>
                                <?php
                                }else if($tabs['fieldType'] == 'date') { ?>
                                  <div class="form-group <?php if($tabs['isRequired'] == 'yes') echo 'required'; ?>">
                                    <label class="col-sm-3 control-label">Select Date:</label>
                                    <div class="col-sm-6">
                                      <div class="input-group date">
                                        <input type="text" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_value][]" value="<?php if(isset($tabs['fieldOptions']['option_id'])) echo $tabs['fieldOptions']['option_id']; ?>" class="form-control">
                                        <span class="input-group-btn">
                                          <button type="button" class="btn btn-default">
                                            <i class="fa fa-calendar"></i>
                                          </button>
                                        </span>
                                      </div>
                                    </div>
                                  </div>
                                <?php
                                }else if($tabs['fieldType'] == 'time') { ?>
                                  <div class="form-group <?php if($tabs['isRequired'] == 'yes') echo 'required'; ?>">
                                    <label class="col-sm-3 control-label">Enter Text:</label>
                                    <div class="col-sm-6">
                                      <div class="input-group time">
                                         <input class="form-control" type="text" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_value][]" value="<?php if(isset($tabs['fieldOptions']['option_id'])) echo $tabs['fieldOptions']['option_id']; ?>" >
                                        <span class="input-group-btn">
                                          <button type="button" class="btn btn-default">
                                            <i class="fa fa-clock-o"></i>
                                          </button>
                                        </span>
                                      </div>
                                    </div>
                                  </div>
                                  <?php
                                  }else if($tabs['fieldType'] == 'datetime') { ?>
                                    <div class="form-group  <?php if($tabs['isRequired'] == 'yes') echo 'required'; ?>">
                                      <label class="col-sm-3 control-label">Select date-time:</label>
                                      <div class="col-sm-6">
                                        <div class="input-group datetime">
                                          <input type="text" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_value][]" value="<?php if(isset($tabs['fieldOptions']['option_id'])) echo $tabs['fieldOptions']['option_id']; ?>" class="form-control">
                                          <span class="input-group-btn">
                                            <button type="button" class="btn btn-default">
                                              <i class="fa fa-clock-o"></i>
                                            </button>
                                          </span>
                                        </div>
                                      </div>
                                    </div>
                                  <?php
                                  } ?>
                            </div>
                          <?php $tabCount++; $wkcustom_option_row++;
                        }
                      } ?>
                  </div>
                </div>

              </div>
            </div>
            <script type="text/javascript">

            $('#vtab-option a:first').tab('show');
              tabCount = '<?php echo $tabCount; ?>';
              wkcustom_option_row = '<?php echo $wkcustom_option_row; ?>';
              $('select[name="wkcustomfield"]').on('change',function(){
                value = $(this).val();
                if(value == ''){
                  return;
                }

                if($('body').find('[field-id = wkoption-'+value+']').length){
                  return;
                }
              fieldType = $('option:selected', this).attr('data-type');
              fieldName = $('option:selected', this).attr('data-name');
              fieldDes = $('option:selected', this).attr('data-des');
              fieldIsRequired = $('option:selected', this).attr('data-isRequired');
              tab = '<li><a href="#wktab-option-'+tabCount+'" data-toggle="tab" id="wkoption-'+tabCount+'" field-id = "wkoption-'+value+'"><i class="fa fa-minus-circle" onclick="$(\'#wkoption-' + tabCount + '\').remove(); $(\'#wktab-option-' + tabCount + '\').remove(); $(\'#vtab-option a:first\').trigger(\'click\'); return false;" /></i>&nbsp;'+fieldName+'</a></li>';
              $('#optionSelector').before(tab);
              html  = '';
              html += '<input type="hidden" name="product_custom_field['+wkcustom_option_row+'][custom_field_name]" value="'+fieldName+'">';
              html += '<input type="hidden" name="product_custom_field['+wkcustom_option_row+'][custom_field_type]" value="'+fieldType+'">';
              html += '<input type="hidden" name="product_custom_field['+wkcustom_option_row+'][custom_field_id]" value="'+value+'">';
              html += '<input type="hidden" name="product_custom_field['+wkcustom_option_row+'][custom_field_des]" value="'+fieldDes+'">';
              html += '<input type="hidden" name="product_custom_field['+wkcustom_option_row+'][custom_field_is_required]" value="'+fieldIsRequired+'">';
              if(fieldIsRequired == 'yes'){
                required = 'required';
              }else{
                required = '';
              }
              if(fieldType == "textarea"){

                html += '<div class="form-group '+required+' "><label class="col-sm-3 control-label"><?php echo $entry_enter_text; ?></label>';
                html += '<div class="col-sm-9"><textarea class="form-control" id="" value="" name="product_custom_field['+wkcustom_option_row+'][custom_field_value][]" row="7"></textarea></div></div>';
                addtoBody(html);

              }else if(fieldType == "text"){

                html += '<div class="form-group '+required+'"><label class="col-sm-3 control-label"><?php echo $entry_enter_text; ?></label>';
                html += '<div class="col-sm-9"><input type="text" class="form-control" name="product_custom_field['+wkcustom_option_row+'][custom_field_value][]" /></div></div>';
                addtoBody(html);

              }else if(fieldType == "time"){

                html += '<div class="form-group '+required+'"><label class="col-sm-3 control-label"><?php echo $entry_select_time; ?></label>';
                html += '<div class="col-sm-6"><div class="input-group time"><input type="text" name="product_custom_field['+wkcustom_option_row+'][custom_field_value][]" class="form-control" /><span class="input-group-btn"><button class="btn btn-default" type="button"><i class="fa fa-clock-o"></i></button</span></div</div></div>';

                addtoBody(html);

              }else if(fieldType == "datetime"){

                html += '<div class="form-group '+required+'"><label class="col-sm-3 control-label"><?php echo $entry_select_datetime; ?></label>';
                html += '<div class="col-sm-6"><div class="input-group datetime"><input type="text" name="product_custom_field['+wkcustom_option_row+'][custom_field_value][]" class="form-control" /><span class="input-group-btn"><button class="btn btn-default" type="button"><i class="fa fa-calendar"></i></button</span></div</div></div>';

                addtoBody(html);

              }else if(fieldType == "date"){

                html += '<div class="form-group '+required+'">';
                html += '<label class="col-sm-3 control-label"><?php echo $entry_select_date; ?></label>';
                html += '<div class="col-sm-6"><div class="input-group date">';
                html += '<input type="text" name="product_custom_field[<?php echo $wkcustom_option_row; ?>][custom_field_value][]" class="form-control">';
                html += '<span class="input-group-btn"><button type="button" class="btn btn-default"><i class="fa fa-calendar"></i></button></span></div></div></div>';

                addtoBody(html);

              }else{
                $.ajax({
                  url:'index.php?route=wkcustomfield/wkcustomfield/getOptions&token=<?php echo $token; ?>',
                  data:'&value='+value,
                  dataType:'json',
                  type:'post',
                  success:function(data){
                    innerHtml = '';
                    if(fieldType == "select"){
                      html += '<div class="form-group '+required+'"><label class="col-sm-3 control-label">Options</label><div class="col-sm-9" >';
                    }else{
                      html += '<div class="form-group '+required+'"><label class="control-label">Options</label><div>';
                    }
                    $.each(data, function(key,val){
                      if(fieldType == "select"){
                        innerHtml += '<option value="' + val.optionId +'">' + val.optionValue + '</option>'
                      }else if(fieldType == "checkbox"){

                        html += '<div class="radio checkbox"><label for="'+ wkcustom_option_row + val.optionId +'"><input type='+fieldType+' id="'+ wkcustom_option_row + val.optionId +'" value="'+val.optionId+'" name="product_custom_field['+wkcustom_option_row+'][custom_field_value][]">'+val.optionValue+'</lable></div>';

                      }else{

                        html += '<div class="radio checkbox"><label for="'+ wkcustom_option_row + val.optionId +'"><input type='+fieldType+' id="'+ wkcustom_option_row + val.optionId +'" value="'+val.optionId+'" value="'+val.optionId+'" name="product_custom_field['+wkcustom_option_row+'][custom_field_value][]">'+val.optionValue+'</lable></div>';

                      }
                    });
                    if(fieldType == "select") {
                      html += '<select class="form-control" name="product_custom_field['+wkcustom_option_row+'][custom_field_value][]">'+innerHtml+'</select>';
                    }
                    addtoBody(html);
                  }
                })
              }
            });

            function addtoBody(html){
              html = '<div id="wktab-option-'+tabCount+'" class="tab-pane"><div class="alert alert-info"><i class="fa fa-info-circle"></i> ' + fieldDes + '</div>' + html + '</div></div></div>';
              $('#wk_customfieldcontent').append(html);
              $('#wkoption-' + tabCount).trigger('click');
              tabCount++;
              wkcustom_option_row++;

              $('.date').datetimepicker({
                pickTime: false
              });

              $('.time').datetimepicker({
                pickDate: false
              });

              $('.datetime').datetimepicker({
                pickDate: true,
                pickTime: true
              });
            }
          </script>
          <!--Marketplace Customfield -->
                              ]]></add>
                </operation>
        </file>
        <file path="admin/controller/catalog/product.php">
            <operation>
                <search><![CDATA[
                        $this->response->setOutput($this->load->view('catalog/product_form', $data));
                        ]]></search>
                        <add position="before"><![CDATA[

                            if(isset($this->request->get['product_id'])){
                                $data['product_id_text'] = '&product_id='.$this->request->get['product_id'];
                            }else{
                                $data['product_id_text'] = '';
                            }
                              ]]></add>
                </operation>
                <operation>
                        <search><![CDATA[
                        $this->response->redirect($this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true));
                        ]]></search>
                        <add position="replace"><![CDATA[
                        if (isset($this->request->get['mpcheck'])) {
                            $this->response->redirect($this->url->link('customerpartner/product', 'token=' . $this->session->data['token'] . $url, true));
                        } else {
                            $this->response->redirect($this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true));
                        }
                              ]]></add>
                </operation>
                <operation>
                        <search><![CDATA[
                        $data['cancel'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true);
                        ]]></search>
                        <add position="after"><![CDATA[
                if (isset($this->request->get['mpcheck'])) {
                    if (!isset($this->request->get['product_id'])) {
                        $data['action'] = $this->url->link('catalog/product/add', 'token=' . $this->session->data['token'] . $url . '&mpcheck=1', true);
                    } else {
                        $data['action'] = $this->url->link('catalog/product/edit', 'token=' . $this->session->data['token'] . '&mpcheck=1&product_id=' . $this->request->get['product_id'] . $url, true);
                    }

                    $data['cancel'] = $this->url->link('customerpartner/product', 'token=' . $this->session->data['token'] . $url, true);
                } else {
                    if (!isset($this->request->get['product_id'])) {
                        $data['action'] = $this->url->link('catalog/product/add', 'token=' . $this->session->data['token'] . $url, true);
                    } else {
                        $data['action'] = $this->url->link('catalog/product/edit', 'token=' . $this->session->data['token'] . '&product_id=' . $this->request->get['product_id'] . $url, true);
                    }

                    $data['cancel'] = $this->url->link('catalog/product', 'token=' . $this->session->data['token'] . $url, true);
                }
                              ]]></add>
                </operation>
                <operation>
                        <search><![CDATA[
                        $this->model_catalog_product->editProduct($this->request->get['product_id'], $this->request->post);
                        ]]></search>
                        <add position="before"><![CDATA[
                            if($this->config->get('marketplace_status')) {
                                    $this->load->model("wkcustomfield/wkcustomfield");
                                    $wkcustomFields = array();
                                    if(isset($this->request->post['product_custom_field'])){
                                        $data = $this->request->post['product_custom_field'];
                                    }else{
                                        $data = '';
                                    }
                                    $this->model_wkcustomfield_wkcustomfield->editCustomFields($data,$this->request->get['product_id']);
                            }
                              ]]></add>
                </operation>
                <operation>
                        <search><![CDATA[
                        $this->model_catalog_product->addProduct($this->request->post);
                        ]]></search>
                        <add position="replace"><![CDATA[
                            if($this->config->get('marketplace_status')) {
                                    $product_id = $this->model_catalog_product->addProduct($this->request->post);
                                    $this->load->model("wkcustomfield/wkcustomfield");
                                    $wkcustomFields = array();
                                    if(isset($this->request->post['product_custom_field'])){
                                        $this->model_wkcustomfield_wkcustomfield->addCustomFields($this->request->post['product_custom_field'],$product_id);
                                    }
                            }else{
                                $this->model_catalog_product->addProduct($this->request->post);
                            }
                              ]]></add>
                </operation>
                <operation>
                        <search><![CDATA[
                        $this->load->model('design/layout');
                        ]]></search>
                        <add position="before"><![CDATA[
        /**
         * customfield
         */
        $this->language->load("wkcustomfield/wkcustomfield");
        $this->load->model("wkcustomfield/wkcustomfield");
        $wkcustomFields = array();
        $data['wkcustomFields'] = $this->model_wkcustomfield_wkcustomfield->getOptionList();

        $data['text_custom_field'] = $this->language->get('text_custom_field');
        $data['entry_select_option'] = $this->language->get('entry_select_option');
        $data['entry_select_date'] = $this->language->get('entry_select_date');
        $data['entry_select_datetime'] = $this->language->get('entry_select_datetime');
        $data['entry_select_time'] = $this->language->get('entry_select_time');
        $data['entry_enter_text'] = $this->language->get('entry_enter_text');

        if(isset($this->request->get['product_id']) || isset($this->request->post['product_custom_field'])){
            if(isset($this->request->get['product_id'])){
                $product_id = $this->request->get['product_id'];
            } else {
                $product_id = 0;
            }
            $data['wkPreCustomFields'] = array();
            $wkPreCustomFieldOptions = array();
            $wkPreCustomFields = $this->model_wkcustomfield_wkcustomfield->getProductFields($product_id);
            if(isset($this->request->post['product_custom_field'])){
                foreach ($this->request->post['product_custom_field'] as $key => $value) {
                    if(!isset($wkPreCustomFields[$key])){
                        $wkPreCustomFields[] = array(
                            'fieldId' => $value['custom_field_id'],
                            'fieldName' => $value['custom_field_name'],
                            'fieldType' => $value['custom_field_type'],
                            'fieldDescription' => $value['custom_field_des'],
                            'id' => '',
                            'isRequired' => $value['custom_field_is_required'],
                        );
                    }
                }
            }
            foreach($wkPreCustomFields as $field){
                $wkPreCustomFieldOptions = $this->model_wkcustomfield_wkcustomfield->getOptions($field['fieldId']);
                if($field['fieldType'] == 'select' || $field['fieldType'] == 'checkbox' || $field['fieldType'] == 'radio' ){
                    $wkPreCustomProductFieldOptions = $this->model_wkcustomfield_wkcustomfield->getProductFieldOptions($product_id,$field['fieldId'],$field['id']);
                } else {
                    $wkPreCustomProductFieldOptions = $this->model_wkcustomfield_wkcustomfield->getProductFieldOptionValue($product_id,$field['fieldId'],$field['id']);
                }
                $data['wkPreCustomFields'][] = array(
                    'fieldId'       => $field['fieldId'],
                    'fieldName'     => $field['fieldName'],
                    'fieldType'     => $field['fieldType'],
                    'fieldDes'      => $field['fieldDescription'],
                    'productFieldId'      => $field['id'],
                    'isRequired'    => $field['isRequired'],
                    'fieldOptions'  => $wkPreCustomProductFieldOptions,
                    'preFieldOptions' => $wkPreCustomFieldOptions,
                );
            }
        }

        if (isset($this->error['customFieldError'])) {
            $data['customFieldError'] = $this->error['customFieldError'];
        } else {
            $data['customFieldError'] = array();
        }

        /**
         * customfield
         */
                              ]]></add>
                </operation>
                <operation>
                        <search><![CDATA[
                        if ($this->error && !isset($this->error['warning'])) {
                        ]]></search>
                        <add position="before"><![CDATA[
        /**
         * customfield
         */
        $customfielddata = array();
        if(isset($this->request->post['product_custom_field'])){
            $customfielddata = $this->request->post['product_custom_field'];
        }
        foreach ($customfielddata as $key => $value) {
            if(isset($value['custom_field_is_required']) && (($value['custom_field_is_required'] == 'yes' && isset($value['custom_field_value']) && $value['custom_field_value'][0] == '' ) || ($value['custom_field_is_required'] == 'yes' && !isset($value['custom_field_value'])))) {
                $this->error['customFieldError'][] = $value['custom_field_id'];
            }
        }
        if(isset($this->error['customFieldError'])) {
            $this->error['warning'] = $this->language->get('error_warning');
        }

        /**
         * customfield
         */
                              ]]></add>
                </operation>
        </file>
        <!-- end here -->
</modification>
