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

<modification>
    <name>Change-MP-Paths</name>
    <version>1.0.0</version>
    <code>All SEF urls</code>
    <author>Webkul</author>
    <link>http://webkul.com</link>

    <file path="catalog/controller/startup/seo_url.php">
        <operation>
            <search><![CDATA[
                $this->request->get['route'] = 'error/not_found';
                ]]></search>
            <add position="before" offset="1"><![CDATA[
                }elseif($this->config->get('module_marketplace_status') && $this->config->get('marketplace_useseo') AND $this->request->get['_route_']=='Marketplace-Collection'){
                    $this->request->get['route'] =  'customerpartner/profile/collection';
                }elseif ($this->config->get('module_marketplace_status') && $this->config->get('marketplace_useseo') AND is_array($this->config->get('marketplace_SefUrlsvalue')) AND (in_array($this->request->get['_route_'],$this->config->get('marketplace_SefUrlsvalue')) || in_array(current(explode('/',$this->request->get['_route_'])),$this->config->get('marketplace_SefUrlsvalue')) )) {
                    $_route_ = explode('/',$this->request->get['_route_']);

                    $sefKey = array_search($_route_[0],$this->config->get('marketplace_SefUrlsvalue'));

                    $wkSefUrlspath = $this->config->get('marketplace_SefUrlspath');

                    if(isset($wkSefUrlspath[$sefKey])) {

                        if($wkSefUrlspath[$sefKey]=='customerpartner/profile' AND isset($_route_[1])) {

                            $query = $this->db->query("SELECT customer_id FROM " . DB_PREFIX . "customerpartner_to_customer WHERE `screenname` = '" . $this->db->escape($_route_[1]) . "'");
                            if ($query->num_rows) {
                                if($query->row['customer_id']){
                                   $this->request->get['id'] = $query->row['customer_id'];
                                }
                            }
                        $this->request->get['route'] = 'customerpartner/profile';

                    } elseif($wkSefUrlspath[$sefKey]=='product/product' && in_array('product/product',$this->config->get('marketplace_SefUrlspath'))) {
                    $new_route = str_replace($this->config->get('marketplace_product_seo_page_ext'),'',$this->request->get['_route_']);
                    $product_name = false;
                    if($this->config->get('marketplace_product_seo_format')) {
                        if($this->config->get('marketplace_product_seo_format')=='1') {
                            $mpparts = explode('/', $new_route);
                            if(isset($mpparts[1]) ) {
                                $product_name = $mpparts[1];
                            }
                        } else if($this->config->get('marketplace_product_seo_format')=='2') {
                           $mpparts = explode($this->config->get('marketplace_product_seo_default_name').'-',$new_route,2);
                           if (!isset($mpparts[1])) {
                            $mpparts = explode('/',$mpparts[0],2);

                            if (isset($mpparts[1])) {
                              $mpparts = explode('-',$mpparts[1],2);
                            }
                           }

                            if(isset($mpparts[1]))
                                $product_name = $mpparts[1];
                        } else if($this->config->get('marketplace_product_seo_format')=='3') {
                            $mpparts = explode('/',$new_route);
                            if($mpparts[1])
                                $product_name = $mpparts[1];
                        }
                    }
                    if ($product_name) {
                        $query = $this->db->query("SELECT * FROM " . DB_PREFIX . "seo_url WHERE keyword = '" . $this->db->escape($product_name) . "'");

                        if ($query->num_rows) {
                            $url = explode('=', $query->row['query']);

                            if ($url[0] == 'product_id') {
                                $this->request->get['product_id'] = $url[1];
                            }
                        }

                        if(!$query->num_rows AND $this->config->get('marketplace_product_seo_product_name')) {
                            $product_name = str_replace('-', ' ', $product_name);
                            $query = $this->db->query("SELECT pd.product_id FROM ".DB_PREFIX."product_description pd WHERE pd.name = '".$this->db->escape($product_name)."' AND pd.language_id = '".$this->config->get('config_language_id')."'");

                            if ($query->num_rows)
                                $this->request->get['product_id'] = $query->row['product_id'];
                        }

                        $this->request->get['route'] = 'product/product';

                    }

                }else{
                    $this->request->get['route'] =  $wkSefUrlspath[$sefKey];
                }

            }
            ]]></add>
        </operation>

        <operation>

            <search><![CDATA[} elseif ($key == 'path') {]]></search>
            <add position="before"><![CDATA[

                }elseif($this->config->get('module_marketplace_status') && $this->config->get('marketplace_useseo') AND $data['route'] == 'customerpartner/profile/collection'){

                    $url .= '/Marketplace-Collection' ;
                    unset($data[$key]);
                }elseif($this->config->get('module_marketplace_status') && $this->config->get('marketplace_useseo') AND $data['route'] == 'product/product' AND isset($data['product_id']) AND is_array($this->config->get('marketplace_SefUrlspath')) AND in_array($data['route'],$this->config->get('marketplace_SefUrlspath')) ) {
                    $sellerDetail = '';
                    $sellerDetails = $this->db->query("SELECT c2c.screenname,c2c.companyname,c.firstname as sellername FROM ".DB_PREFIX."customerpartner_to_product c2p LEFT JOIN ".DB_PREFIX."product p ON (p.product_id=c2p.product_id) LEFT JOIN ".DB_PREFIX."customerpartner_to_customer c2c ON (c2p.customer_id=c2c.customer_id) LEFT JOIN ".DB_PREFIX."customer c ON (c.customer_id=c2c.customer_id) WHERE c2p.product_id = '".$data['product_id']."' ")->row;

                    if(isset($sellerDetails[$this->config->get('marketplace_product_seo_name')]) && $sellerDetails[$this->config->get('marketplace_product_seo_name')] ) {
                        $sellerDetail = $sellerDetails[$this->config->get('marketplace_product_seo_name')];
                    } else {
                        $sellerDetail = $this->config->get('marketplace_product_seo_default_name');
                    }
                    $keyword = $this->db->query("SELECT keyword FROM ".DB_PREFIX."seo_url WHERE query = 'product_id=" . (int)$data['product_id'] . "' ")->row;

                    if(isset($keyword['keyword']) && $keyword['keyword']) {
                        $keyword = $keyword['keyword'];
                        unset($data['product_id']);
                    } else if($this->config->get('marketplace_product_seo_name')) {

                        $key_word = $this->db->query("SELECT name FROM ".DB_PREFIX."product_description pd WHERE product_id = '".$data['product_id']."' AND language_id = '".$this->config->get('config_language_id')."' ")->row;

                        if(isset($key_word['name'])) {
                            $keyword = str_replace(' ','-',$key_word['name']);
                        } else {
                            $keyword = '';
                        }
                    }
                    $sefKey = array_search($data['route'],$this->config->get('marketplace_SefUrlspath'));
                    $wkSefUrlsvalue = $this->config->get('marketplace_SefUrlsvalue');
                    if(isset($wkSefUrlsvalue[$sefKey]) && $wkSefUrlsvalue[$sefKey]) {
                        $url .= '/'.$wkSefUrlsvalue[$sefKey];
                    } else {
                        $url .= '';
                    }
                    if($sellerDetail) {
                        if($this->config->get('marketplace_product_seo_format') == '1') {
                            $url .= '/'.$keyword;
                        } else if($this->config->get('marketplace_product_seo_format') == '2') {
                            $url .= '/'.str_replace(array(' ', '-'),'_',$sellerDetail).'-'.$keyword;
                        } else if ($this->config->get('marketplace_product_seo_format') == '3') {
                            $url .= '/'.$keyword.'/'.str_replace(' ','-',$sellerDetail);
                        }
                        if($this->config->get('marketplace_product_seo_page_ext')) {
                            $url .= $this->config->get('marketplace_product_seo_page_ext');
                        }
                        unset($data[$key]);
                    } else {

                        $sefKey = array_search($data['route'],$this->config->get('marketplace_SefUrlspath'));
                        $wkSefUrlsvalue = $this->config->get('marketplace_SefUrlsvalue');

                        if(isset($wkSefUrlsvalue[$sefKey])){
                            if($keyword){
                                $url .=  '/'.$keyword;
                            }
                            if($this->config->get('marketplace_product_seo_page_ext')) {
                                $url .= $this->config->get('marketplace_product_seo_page_ext');
                            }
                            unset($data[$key]);
                        }
                    }
                    unset($data['product_id']);
                } elseif ($this->config->get('module_marketplace_status') && $this->config->get('marketplace_useseo') AND is_array($this->config->get('marketplace_SefUrlspath')) AND in_array($data['route'],$this->config->get('marketplace_SefUrlspath'))) {
                    $sefKey = array_search($data['route'],$this->config->get('marketplace_SefUrlspath'));

                    $wkSefUrlsvalue = $this->config->get('marketplace_SefUrlsvalue');
                    if(isset($wkSefUrlsvalue[$sefKey])){
                        if($data['route']=='customerpartner/profile'){
                            if($key == 'id'){
                                $url .=  '/'.$wkSefUrlsvalue[$sefKey];

                                $query = $this->db->query("SELECT screenname FROM " . DB_PREFIX . "customerpartner_to_customer WHERE `customer_id` = '" . (int)$data[$key] . "'");
                                if ($query->num_rows) {

                                   if(trim($query->row['screenname'])){
                                      $url .= '/' . $query->row['screenname'];
                                    }else{
                                      $url .= '';
                                    }
                                    unset($data[$key]);
                                }
                            }
                        }elseif(($data['route'] != 'product/product') && ($data['route'] != 'customerpartner/profile')){
                            $url .=  '/'.$wkSefUrlsvalue[$sefKey];
                            unset($data[$key]);
                        }
                    }

            ]]></add>
        </operation>
    </file>

    <file path="catalog/controller/checkout/confirm.php">
        <operation>
            <search><![CDATA[
                'price'      => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')), $this->session->data['currency']),
            ]]></search>
            <add position="replace"><![CDATA[
                'price'      => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))+$product['commission_amount'], $this->session->data['currency']),
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[
                'total'      => $this->currency->format($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'], $this->session->data['currency']),
            ]]></search>
            <add position="replace"><![CDATA[
                'total'      => $this->currency->format(($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))+$product['commission_amount']) * $product['quantity'], $this->session->data['currency']),
            ]]></add>
        </operation>
    </file>

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

      <operation>
          <search><![CDATA[
            public function getProducts() {
          ]]></search>
          <add position="before"><![CDATA[
            public function calculateCommission($product,$customer_id) {

              if($product) {
                $categories_array = $this->db->query("SELECT p2c.category_id,c.parent_id FROM ".DB_PREFIX."product_to_category p2c LEFT JOIN ".DB_PREFIX."category c ON (p2c.category_id = c.category_id) WHERE p2c.product_id = '".(int)$product['product_id']."' ORDER BY p2c.product_id ");

                if($this->config->get('marketplace_commissionworkedon'))
                  $categories = $categories_array->rows;
                else
                  $categories = array($categories_array->row);

                //get commission array for priority
                $commission = $this->config->get('marketplace_boxcommission');
                $commission_amount = 0;
                $commission_type = '';

                if($commission)
                  foreach($commission as $various) {
                    switch ($various) {
                      case 'category': //get all parent category according to product and process
                        if(isset($categories[0]) && $categories[0]){

                          foreach($categories as $category) {
                            if($category['parent_id']==0){
                              $category_commission = $query = $this->db->query("SELECT * FROM ".DB_PREFIX."customerpartner_commission_category WHERE category_id = '" . (int)$category['category_id'] . "'")->row;
                              if($category_commission){
                                $commission_amount += ( $category_commission['percentage'] ? ($category_commission['percentage']*$product['product_total']/100) : 0 ) + $category_commission['fixed'];
                              }
                            }
                          }
                          $commission_type = 'Category Based';
                          if($commission_amount)
                            break;
                        }

                      case 'category_child': //get all child category according to product and process
                        if(isset($categories[0]) && $categories[0]){

                          foreach($categories as $category){
                            if($category['parent_id'] > 0){
                              $category_commission = $query = $this->db->query("SELECT * FROM ".DB_PREFIX."customerpartner_commission_category WHERE category_id = '" . (int)$category['category_id'] . "'")->row;
                              if($category_commission){
                                $commission_amount += ( $category_commission['percentage'] ? ($category_commission['percentage']*$product['product_total']/100) : 0 ) + $category_commission['fixed'];
                              }
                            }
                          }

                          $commission_type = 'Category Child Based';
                          if($commission_amount)
                            break;
                        }

                      default: //just get all amount and process on that (precentage based)
                        $customer_commission = $query = $this->db->query("SELECT commission FROM ".DB_PREFIX."customerpartner_to_customer WHERE customer_id = '" . (int)$customer_id . "'")->row;
                        if($customer_commission) {
                          $commission_amount += $customer_commission['commission'] ? ($customer_commission['commission']*$product['product_total']/100) : 0;
                        }

                        $commission_type = 'Partner Fixed Based';
                        break;
                    }
                    if($commission_amount)
                      break;
                  }

                  if($this->config->get('module_wk_seller_group_status')) {
					
                    $result = end($this->db->query("SELECT * FROM ".DB_PREFIX."seller_group_customer WHERE customer_id = '" . $customer_id."'")->rows);
                    if($result && !$result['suspended']) {

                      $categories = $this->db->query("SELECT category_id FROM ".DB_PREFIX."product_to_category WHERE product_id = '" . (int)$product['product_id']."' ")->rows;
                      
                      foreach ($categories as $category) {
                        if ($category && isset($category['category_id']) && $category['category_id']) {
                          $groupCommission = $this->db->query("SELECT percentage,fixed FROM ".DB_PREFIX."seller_group_commission_categorywise WHERE category_id = '" . $category['category_id'] . "' AND seller_id = '" . $customer_id . "' AND group_id = '" . $result['gid']."' ")->row;
                          if (empty($groupCommission)) {
                            $groupCommission = $this->db->query("SELECT customerDefaultGroupCommissionPercentage as percentage,customerDefaultGroupCommissionFixed as fixed FROM ".DB_PREFIX."seller_group_customer WHERE customer_id = '" . $customer_id."' AND gid = '" . $result['gid'] . "' ")->row;
                          }
                        } else {
                          $groupCommission = $this->db->query("SELECT customerDefaultGroupCommissionPercentage as percentage,customerDefaultGroupCommissionFixed as fixed FROM ".DB_PREFIX."seller_group_customer WHERE customer_id = '" . $customer_id."' AND gid = '" .  $result['gid'] ."' ")->row;
                        }
                      }
                     	if(isset($groupCommission) && $groupCommission) {
                        $commission_amount += ( $groupCommission['percentage'] ? ($groupCommission['percentage']*$product['product_total']/100) : 0 ) + $groupCommission['fixed'];
                      }
                      $commission_type = 'Membership Based';
                    }
                  }
                $return_array = array(
                  'commission' => $commission_amount,
                  'customer' => $product['product_total']- $commission_amount,
                  'type' => $commission_type,
                );
                return($return_array);
              }
            }
          ]]></add>
      </operation>

      <operation>
          <search><![CDATA[
            'price'           => ($price + $option_price),
          ]]></search>
          <add position="after"><![CDATA[
            'commission_amount'  => $commission_amount,
          ]]></add>
      </operation>

      <operation>
          <search><![CDATA[
            'total'           => ($price + $option_price) * $cart['quantity'],
          ]]></search>
          <add position="replace"><![CDATA[
            'total'           => ($price + $option_price + $commission_amount) * $cart['quantity'],
          ]]></add>
      </operation>

        <operation>
            <search><![CDATA[
                $total += $this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax')) * $product['quantity'];
            ]]></search>
            <add position="replace"><![CDATA[
                $total += ($this->tax->calculate($product['price'], $product['tax_class_id'], $this->config->get('config_tax'))+$product['commission_amount']) * $product['quantity'];
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[
              $product_data[] = array(
            ]]></search>
            <add position="before"><![CDATA[
              $commission_amount = 0;
              if ($this->config->get('module_marketplace_status')) {
                 $check_seller_product = $this->db->query("SELECT * FROM ".DB_PREFIX."customerpartner_to_product WHERE product_id = '".$product_query->row['product_id']."'")->row;
                 if ($check_seller_product) {
                  if ($this->config->get('marketplace_commission_tax')) {
                    $commission_array = $this->calculateCommission(array('product_id'=> $product_query->row['product_id'], 'product_total'=> $this->tax->calculate(($price + $option_price), $product_query->row['tax_class_id'], $this->config->get('config_tax'))),$check_seller_product['customer_id']);
                  }else{
                    $commission_array = $this->calculateCommission(array('product_id'=>$product_query->row['product_id'], 'product_total'=>($price + $option_price)),$check_seller_product['customer_id']);
                  }

                  if($commission_array && isset($commission_array['commission']) && $this->config->get('marketplace_commission_unit_price')){
                        $commission_amount = $commission_array['commission'];
                  }
                }
              }
            ]]></add>
        </operation>

    </file>

    <file path="system/library/cart/cart.php">
      <operation>
          <search><![CDATA[
            $this->data[] = array(
          ]]></search>
          <add position="before"><![CDATA[
            $commission_amount = 0;
            if ($this->config->get('module_marketplace_status')) {
               $check_seller_product = $this->db->query("SELECT * FROM ".DB_PREFIX."customerpartner_to_product WHERE product_id = '".$product_query->row['product_id']."'")->row;
               if ($check_seller_product) {
                if ($this->config->get('marketplace_commission_tax')) {
                  $commission_array = $this->calculateCommission(array('product_id'=> $product_query->row['product_id'], 'product_total'=> $this->tax->calculate(($price + $option_price), $product_query->row['tax_class_id'], $this->config->get('config_tax'))),$check_seller_product['customer_id']);
                }else{
                  $commission_array = $this->calculateCommission(array('product_id'=>$product_query->row['product_id'], 'product_total'=>($price + $option_price)),$check_seller_product['customer_id']);
                }

                if($commission_array && isset($commission_array['commission']) && $this->config->get('marketplace_commission_unit_price')){
                      $commission_amount = $commission_array['commission'];
                }
              }
            }
          ]]></add>
      </operation>
       <operation>
          <search><![CDATA[
           'price'           => ($price + $option_price)
          ]]></search>
          <add position="replace"><![CDATA[
           'price'           => ($price + $option_price) + $commission_amount_total,
          ]]></add>
      </operation>
       <operation>
          <search><![CDATA[
            'price'           => ($price + $option_price),
          ]]></search>
          <add position="replace"><![CDATA[
             'price'           => ($price + $option_price + $commission_amount),
          ]]></add>
      </operation>
    </file>

    <file path="admin/view/template/catalog/product_form.twig">
        <operation>
            <search><![CDATA[
              $('input[name=\'category\']').val('');
            ]]></search>
            <add position="before"><![CDATA[
              addCategoryAttribute(item);
            ]]></add>
        </operation>

        <operation>
            <search><![CDATA[
                function addAttribute() {
            ]]></search>
            <add position="before"><![CDATA[
              function addCategoryAttribute(item)  {

                if (item.value) {
                  $.ajax({
                    url: 'index.php?route=customerpartner/categorymapping/categoryAttribute&user_token={{ user_token }}&category_id=' + item.value,
                    dataType: 'json',
                    success: function(json) {
                      $.each(json, function() {
                          addAttribute();
                          var category_attribute_row = attribute_row -1;
                          $('input[name=\'product_attribute[' + category_attribute_row + '][name]\']').val(this.name);
                          $('input[name=\'product_attribute[' + category_attribute_row + '][attribute_id]\']').val(this.attribute_id);
                      });
                    }
                  });
                }
              }
            ]]></add>
        </operation>
    </file>
    <file path="catalog/controller/checkout/shipping_method.php">

    <operation>
        <search><![CDATA[
          $this->response->setOutput($this->load->view('checkout/shipping_method', $data));
        ]]></search>
        <add position="before"><![CDATA[
          if (isset($data['shipping_methods']) && isset($data['shipping_methods']['wk_custom_shipping']) && isset($this->session->data['seller_custom_shipping']) && $this->session->data['seller_custom_shipping'] && $this->config->get('shipping_wk_custom_shipping_seller_status')) {
          $data['seller_custom_shipping'] = $this->session->data['seller_custom_shipping'];
          $data['text_seller_name'] = $this->language->get('text_seller_name');
					$data['text_seller_shipping'] = $this->language->get('text_seller_shipping');
          $data['text_event_amount'] = $this->language->get('text_event_amount');
          $data['event_shipping_amount'] = isset($this->session->data['event_shipping_amount']) ? $this->session->data['event_shipping_amount'] : 0;
        }
        ]]></add>
        </operation>

        <operation>
          <search><![CDATA[
          $this->load->model('setting/extension');
          ]]></search>
          <add position="after"><![CDATA[
           if ($this->config->get('shipping_wk_custom_shipping_status')) {
			$this->load->language('extension/shipping/wk_custom_shipping');
			if ($this->config->get('shipping_wk_custom_shipping_priority_status')) {
				$this->load->model('account/customerpartnerorder');
					
				$this->load->model('account/add_shipping_mod');
				$shipping = array();
				$this->load->model('account/customer');
					
					  
				$seller = $this->model_account_customerpartnerorder->sellerAdminData($this->cart->getProducts());
  
				  foreach ($seller as $key => $value) {
						if ($this->config->get('shipping_wk_custom_shipping_seller_details') && $value['seller'] != 'Admin') {	
						
					  $sellername = $this->model_account_customer->getCustomer($value['seller']);
						  $shipping = $this->model_account_add_shipping_mod->getPriorityShipping($value['seller']);
  
						  if (!empty($shipping) && $shipping['status']) {
							foreach ($shipping as $keys => $values) {
							  if ($keys == 'high') {
								$shipping[$keys] = (array)json_decode($shipping[$keys]);
								$shipping[$keys]['text'] = $this->currency->format($shipping[$keys]['amount'],$this->session->data['currency']);
							  } else if ($keys == 'low') {
								$shipping[$keys] = (array)json_decode($shipping[$keys]);
  
								$shipping[$keys]['text'] = $this->currency->format($shipping[$keys]['amount'],$this->session->data['currency']);
							  } else if ($keys == 'medium') {
								$shipping[$keys] = (array)json_decode($shipping[$keys]);
								$shipping[$keys]['text'] = $this->currency->format($shipping[$keys]['amount'],$this->session->data['currency']);
							  } else {
								$shipping[$keys] = $shipping[$keys];
							  }
							}
							$priority_shipping[$value['seller']] = $shipping;
							$priority_shipping[$value['seller']]['name'] = ucfirst($sellername['firstname']) . ' ' . ucfirst($sellername['lastname']);
						  } else {
							$priority_shipping[$value['seller']] = array();
						  }
					  } else if($value['seller'] == 'Admin' || !$this->config->get('shipping_wk_custom_shipping_seller_details') && $value['seller'] != 'Admin') {
						$priority_shipping[0]['high'] = array(
						  'day'    => $this->config->get('shipping_wk_custom_shipping_high_priority_day'),
						  'amount' => $this->config->get('shipping_wk_custom_shipping_high_priority_amount'),
						  'text'	 => $this->currency->format($this->config->get('shipping_wk_custom_shipping_high_priority_amount'),$this->session->data['currency'])
						);
						$priority_shipping[0]['medium'] = array(
						  'day'    => $this->config->get('shipping_wk_custom_shipping_mid_priority_day'),
						  'amount' => $this->config->get('shipping_wk_custom_shipping_mid_priority_amount'),
						  'text'	 => $this->currency->format($this->config->get('shipping_wk_custom_shipping_mid_priority_amount'),$this->session->data['currency'])
						);
            $priority_shipping[0]['low'] = array(
						  'day'    => $this->config->get('shipping_wk_custom_shipping_low_priority_day'),
						  'amount' => $this->config->get('shipping_wk_custom_shipping_low_priority_amount'),
						  'text'	 => $this->currency->format($this->config->get('shipping_wk_custom_shipping_low_priority_amount'),$this->session->data['currency'])
						);
						$priority_shipping[0]['name'] = 'Admin';
					}
				  }
					  $data['text_priority']        = $this->language->get('text_priority');
					  $data['entry_high']           = $this->language->get('entry_high');
					  $data['entry_medium']         = $this->language->get('entry_medium');
					  $data['entry_low']            = $this->language->get('entry_low');
					  $data['text_seller_name']     = $this->language->get('text_seller_name');
					  $data['text_seller_shipping'] = $this->language->get('text_seller_shipping');
					  $data['text_day']             = $this->language->get('text_day');
					  $data['text_duration']        = $this->language->get('text_duration');
					  $data['text_charges']         = $this->language->get('text_charges');
					  $data['text_event_amount']    = $this->language->get('text_event_amount');
					  $data['priority_shipping']    = $priority_shipping;
					  
					}
		   } 

            ]]></add>
      </operation>

      <operation>
          <search><![CDATA[
           $this->session->data['shipping_method'] = $this->session->data['shipping_methods'][$shipping[0]]['quote'][$shipping[1]];
          ]]></search>
          <add position="after"><![CDATA[
          if ($this->session->data['shipping_method']['code'] == 'wk_custom_shipping.wk_custom_shipping') {
            if (isset($this->request->post['shipping_priority']) && is_array($this->request->post['shipping_priority']) && !empty($this->request->post['shipping_priority'])) {
                  $priority_sum = 0;
                  foreach ($this->request->post['shipping_priority'] as $key => $value) {
                    $this->session->data['seller_priority_shipping'][$key]	= $value;
                    $priority_sum += $value;
                  }
                  unset($this->request->post['shipping_priority']);
                  $this->request->post['shipping_priority'] = $priority_sum;
                } else {
                  unset($this->request->post['shipping_priority']);
                  $this->request->post['shipping_priority'] = 0;
                }
            $this->session->data['shipping_method']['cost'] += $this->request->post['shipping_priority'];
            $this->session->data['shipping_method']['text'] = $this->currency->format($this->session->data['shipping_method']['cost'], $this->session->data['currency']);
          } else {
              unset($this->session->data['seller_priority_shipping']);
          }
            ]]></add>
      </operation>
      
    </file>
    <file path="catalog/controller/journal3/checkout.php">
      <operation>
      <search><![CDATA[
      $data['shipping_method_block'] = $this->renderView('journal3/checkout/shipping_method', array(
      ]]></search>
      <add position="before"><![CDATA[
      if ($this->config->get('shipping_wk_custom_shipping_status')) {
          $this->load->language('extension/shipping/wk_custom_shipping');
              $custom_shipping['title'] = $this->config->get('shipping_wk_custom_shipping_title');
          if ($this->config->get('shipping_wk_custom_shipping_priority_status')) {
            $this->load->model('account/customerpartnerorder');
              
            $this->load->model('account/add_shipping_mod');
            $shipping = array();
            $this->load->model('account/customer');
              
                
            $seller = $this->model_account_customerpartnerorder->sellerAdminData($this->cart->getProducts());
      
            foreach ($seller as $key => $value) {
              if ($this->config->get('shipping_wk_custom_shipping_seller_details') && $value['seller'] != 'Admin') {	
                
                  $sellername = $this->model_account_customer->getCustomer($value['seller']);
                $shipping = $this->model_account_add_shipping_mod->getPriorityShipping($value['seller']);
      
                if (!empty($shipping) && $shipping['status']) {
                  foreach ($shipping as $keys => $values) {
                    if ($keys == 'high') {
                      $shipping[$keys] = (array)json_decode($shipping[$keys]);
                      $shipping[$keys]['text'] = $this->currency->format($shipping[$keys]['amount'],$this->session->data['currency']);
                    } else if ($keys == 'low') {
                      $shipping[$keys] = (array)json_decode($shipping[$keys]);
      
                      $shipping[$keys]['text'] = $this->currency->format($shipping[$keys]['amount'],$this->session->data['currency']);
                    } else if ($keys == 'medium') {
                      $shipping[$keys] = (array)json_decode($shipping[$keys]);
                      $shipping[$keys]['text'] = $this->currency->format($shipping[$keys]['amount'],$this->session->data['currency']);
                    } else {
                      $shipping[$keys] = $shipping[$keys];
                    }
                  }
                  $priority_shipping[$value['seller']] = $shipping;
                  $priority_shipping[$value['seller']]['name'] = ucfirst($sellername['firstname']) . ' ' . ucfirst($sellername['lastname']);
                } else {
                $priority_shipping[$value['seller']] = array();
                }
              } else if($value['seller'] == 'Admin' || !$this->config->get('shipping_wk_custom_shipping_seller_details') && $value['seller'] != 'Admin') {
                $priority_shipping[0]['high'] = array(
                  'day'    => $this->config->get('shipping_wk_custom_shipping_high_priority_day'),
                  'amount' => $this->config->get('shipping_wk_custom_shipping_high_priority_amount'),
                  'text'	 => $this->currency->format($this->config->get('shipping_wk_custom_shipping_high_priority_amount'),$this->session->data['currency'])
                );
                $priority_shipping[0]['medium'] = array(
                  'day'    => $this->config->get('shipping_wk_custom_shipping_mid_priority_day'),
                  'amount' => $this->config->get('shipping_wk_custom_shipping_mid_priority_amount'),
                  'text'	 => $this->currency->format($this->config->get('shipping_wk_custom_shipping_mid_priority_amount'),$this->session->data['currency'])
                );
                $priority_shipping[0]['low'] = array(
                  'day'    => $this->config->get('shipping_wk_custom_shipping_low_priority_day'),
                  'amount' => $this->config->get('shipping_wk_custom_shipping_low_priority_amount'),
                  'text'	 => $this->currency->format($this->config->get('shipping_wk_custom_shipping_low_priority_amount'),$this->session->data['currency'])
                );
                $priority_shipping[0]['name'] = 'Admin';
              }
            }
            $custom_shipping['text_priority']        = $this->language->get('text_priority');
            $custom_shipping['entry_high']           = $this->language->get('entry_high');
            $custom_shipping['entry_medium']         = $this->language->get('entry_medium');
            $custom_shipping['entry_low']            = $this->language->get('entry_low');
            $custom_shipping['text_seller_name']     = $this->language->get('text_seller_name');
            $custom_shipping['text_seller_shipping'] = $this->language->get('text_seller_shipping');
            $custom_shipping['text_day']             = $this->language->get('text_day');
            $custom_shipping['text_duration']        = $this->language->get('text_duration');
            $custom_shipping['text_charges']         = $this->language->get('text_charges');
            $custom_shipping['text_event_amount']    = $this->language->get('text_event_amount');
            $custom_shipping['priority_shipping']    = isset($priority_shipping) ? $priority_shipping : array();
            
          }

          if (isset($this->session->data['shipping_methods']) && isset($this->session->data['shipping_methods']['wk_custom_shipping']) && isset($this->session->data['seller_custom_shipping']) && $this->session->data['seller_custom_shipping'] && $this->config->get('shipping_wk_custom_shipping_seller_status')) {
            $custom_shipping['seller_custom_shipping'] = $this->session->data['seller_custom_shipping'];
            $custom_shipping['text_seller_name'] = $this->language->get('text_seller_name');
            $custom_shipping['text_seller_shipping'] = $this->language->get('text_seller_shipping');
            $custom_shipping['text_event_amount'] = $this->language->get('text_event_amount');
            $custom_shipping['event_shipping_amount'] = isset($this->session->data['event_shipping_amount']) ? $this->session->data['event_shipping_amount'] : 0;
          }
        }
      ]]></add>
      </operation>
      <operation>
      <search><![CDATA[
      'error_warning' => sprintf($this->language->get('error_no_shipping'), $this->url->link('information/contact')),
      ]]></search>
      <add position="after"><![CDATA[
      'custom_shipping' => isset($custom_shipping) ? $custom_shipping : array(),
      ]]></add>
      </operation>
    </file>
    <file path="catalog/language/*/checkout/checkout.php">
      <operation>
        <search><![CDATA[
          // Text
        ]]></search>
        <add position="after"><![CDATA[
          $_['text_seller_name']                      = 'Seller Name';
          $_['text_seller_shipping']                      = 'Shipping Applied';
        ]]></add>
        </operation>
    </file>
    <file path="catalog/model/journal3/checkout.php">
    <operation>
    <search><![CDATA[
    $shipping_method = Arr::get($this->session->data, 'shipping_methods.' . $shipping[0] . '.quote.' . $shipping[1]);
    ]]></search>
    <add position="after"><![CDATA[
    if ($shipping_method['code'] == 'wk_custom_shipping.wk_custom_shipping') {
				if (isset($this->request->post['priority']) && $this->request->post['priority']) {
					$sellers = explode('|',$this->request->post['priority']);
					foreach ($sellers as $seller) {
						$shipping_priority = explode('_',$seller);
						$this->session->data['seller_priority_shipping'][$shipping_priority[1]] = $shipping_priority[0];
					}
				} else {
					unset($this->session->data['seller_priority_shipping']);
				}
				if (isset($this->session->data['seller_priority_shipping'])) {
					$priority_sum = 0;
					foreach ($this->session->data['seller_priority_shipping'] as $key => $priority) {
						$priority_sum += $priority;
					}
					$shipping_method['cost'] += $priority_sum;
				}
			} else {
				unset($this->session->data['seller_priority_shipping']);
			}
    ]]></add>
    </operation>
    </file>
    <file path="catalog/view/theme/journal3/template/journal3/checkout/shipping_method.twig">
      <operation>
        <search><![CDATA[
        </label>
        ]]></search>
        <add position="after" offset = "1"><![CDATA[
        <div v-if ="shipping_method.title  == '{{custom_shipping.title}}'">
        {% if custom_shipping is defined and not custom_shipping is empty %}
          {% if custom_shipping.priority_shipping is defined and custom_shipping.priority_shipping %} 
            <p><strong>{{ ccustom_shipping.text_priority }}</strong></p>
            <input type = "hidden" name = "shipping_priority" value = "">
            {% for key,shipping in custom_shipping.priority_shipping %} 
                {% if (shipping is iterable) %} 
                    <strong>{% if (shipping['name'] is defined) %} {{ shipping['name'] }} {% endif %}</strong>
                  {% for keys,priority in shipping %} 
                      {% if (keys == 'high') %} 
                        <div class ="radio">
                          <label><input type="radio" class = "priority" name="shipping_priority_{{ key }}" value="{{ priority['amount'] }}" v-on:change="save_custom()" />{{ entry_high }} : {{ text_duration }} - {% if (priority['day'] is defined and priority['day']) %} {{ priority['day'] }} {% else %} {{ '0' }} {% endif %} {{ text_day }} : {{ text_charges }} - {% if (priority['text'] is defined and priority['text']) %} {{ priority['text'] }} {% endif %} 
                            </label>
                        </div>
                      {% endif %} 
                      {% if (keys == 'medium') %} 
                        <div class ="radio">
                          <label><input type="radio" class = "priority" name="shipping_priority_{{ key }}" value="{{ priority['amount'] }}" v-on:change="save_custom()" />{{ entry_medium }} : {{ text_duration }} -{% if (priority['day'] is defined and priority['day']) %} {{ priority['day'] }} {% else %} {{ '0' }} {% endif %} {{ text_day }} : {{ text_charges }} - {% if (priority['text'] is defined and priority['text']) %} {{ priority['text'] }} {% endif %} 
                            </label>
                        </div>
                      {% endif %} 
                      {% if (keys == 'low') %} 
                        <div class ="radio">
                          <label><input type="radio" class = "priority" name="shipping_priority_{{ key }}" value="{{ priority['amount'] }}" v-on:change="save_custom()" />{{ entry_low }}: {{ text_duration }} - {% if (priority['day'] is defined and priority['day']) %} {{ priority['day'] }} {% else %} {{ '0' }} {% endif %} {{ text_day }} :  {{ text_charges }} - {% if (priority['text'] is defined and priority['text']) %} {{ priority['text'] }} {% endif %} 
                            </label>
                        </div>
                      {% endif %} 
                {% endfor %}
                {% endif %}
                {% endfor %}
                {% endif %}
            {% if custom_shipping.seller_custom_shipping is defined and custom_shipping.seller_custom_shipping %}
              <div class="table-responsive">
               <table class="table table-stripped table-bordered table-hover">
                  <thead>
                    <tr>
                      <th class="text-left">{{ custom_shipping.text_seller_name }}</th>
                      <th class="text-right">{{ custom_shipping.text_seller_shipping }}</th>
                      {% if custom_shipping.event_shipping_amount is defined and custom_shipping.event_shipping_amount %}
                        <th class="text-right">{{ custom_shipping.text_event_amount }}</th>
                      {% endif %}
                    </tr>
                  </thead>
                  <tbody id="sp">
                  {% for key,value in custom_shipping.seller_custom_shipping %}
                    <tr>
                        <td class="text-left">{{ key }}</td>
                        <td class="text-right">{{ value.shipping_price }}</td>
                        {% if custom_shipping.event_shipping_amount is defined and custom_shipping.event_shipping_amount %}
                        <td class="text-right">{{ value.prefix }} {{ value.event_shipping_amount }}</td>
                        {% endif %}
                    </tr>
                  {% endfor %}
            
                  </tbody>
                </table>
              </div>
            {% endif %}
        {% endif %}
        </div>
        ]]></add>
      </operation>
      <operation>
        <search><![CDATA[
        <div class="shippings">
        ]]></search>
        <add position="replace"><![CDATA[
        <div class="shippings" style = "width : 100%">
        ]]></add>
      </operation>
    </file>
    <file path="catalog/view/theme/*/template/checkout/shipping_method.twig">
      <operation>
        <search><![CDATA[
          {{ quote.title }} - {{ quote.text }}</label>
        ]]></search>
        <add position="after" offset="1"><![CDATA[
          {% if quote['code'] == 'shipping_wk_custom_shipping.shipping_wk_custom_shipping' %}
            {% if seller_custom_shipping is defined and seller_custom_shipping %}
              <div class="table-responsive" style="width:50%;">
                <table class="table table-stripped table-bordered table-hover">
                  <thead>
                    <tr>
                      <th class="text-left">{{ text_seller_name }}</th>
                      <th class="text-right">{{ text_seller_shipping }}</th>
                    </tr>
                  </thead>
                  <tbody>
                  {% for key,value in seller_custom_shipping %}
                    <tr>
                        <td class="text-left">{{ key }}</td>
                        <td class="text-right">{{ value }}</td>
                    </tr>
                  {% endfor %}
                  </tbody>
                </table>
              </div>
            {% endif %}
          {% endif %}
        ]]></add>
      </operation>
    </file>

    <file path="admin/controller/catalog/information.php">
      <operation>
        <search><![CDATA[
          $this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true));
        ]]></search>
        <add position="replace"><![CDATA[
          if ($this->config->get('module_marketplace_status') && isset($this->request->get['mpcheck'])) {
              $this->response->redirect($this->url->link('customerpartner/information', 'user_token=' . $this->session->data['user_token'] . $url, true));
          } else {
              $this->response->redirect($this->url->link('catalog/information', 'user_token=' . $this->session->data['user_token'] . $url, true));
          }
        ]]></add>
      </operation>

      <operation>
        <search><![CDATA[
          $data['action'] = $this->url->link('catalog/information/edit', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $this->request->get['information_id'] . $url, true);
        ]]></search>
        <add position="replace"><![CDATA[
          if (isset($this->request->get['mpcheck']) && $this->request->get['mpcheck']) {
            $data['action'] = $this->url->link('catalog/information/edit', 'user_token=' . $this->session->data['user_token'] . '&mpcheck=1&information_id=' . $this->request->get['information_id'] . $url, true);
          } else {
            $data['action'] = $this->url->link('catalog/information/edit', 'user_token=' . $this->session->data['user_token'] . '&information_id=' . $this->request->get['information_id'] . $url, true);
          }
        ]]></add>
      </operation>
    </file>

    <file path="system/engine/loader.php">
      <operation>
        <search><![CDATA[
          $output = $template->render($this->registry->get('config')->get('template_directory') . $route);
        ]]></search>
        <add position="replace"><![CDATA[
          if ($this->config->get('marketplace_separate_view') && isset($this->session->data['marketplace_separate_view']) && $this->session->data['marketplace_separate_view'] == 'separate' && preg_match('/account\/customerpartner/',$route) && isset(explode('/',$route,2)[1])) {
            $output = $template->render('default/template/' . $route);
          } elseif ($this->config->get('marketplace_separate_view') && isset($this->session->data['marketplace_separate_view']) && $this->session->data['marketplace_separate_view'] == 'separate' && preg_match('/common\/filemanager/',$route) && isset(explode('/',$route,2)[1])) {
            $output = $template->render('default/template/common/filemanager');
          } else {
            $output = $template->render($this->registry->get('config')->get('template_directory') . $route);
          }
        ]]></add>
      </operation>
    </file>
     <file path="catalog/controller/checkout/checkout.php">
            <operation>
                    <search><![CDATA[
      public function index() {
                    ]]></search>
                    <add position="before"><![CDATA[
        public function getsellershipping() {
		$json = array ();
		$this->load->model('extension/shipping/wk_custom_shipping');
		$json = $this->model_extension_shipping_wk_custom_shipping->getsellershipping($this->request->post);
		$this->response->addHeader('Content-Type: application/json');
		$this->response->setOutput(json_encode($json));
	}
                         ]]></add>
            </operation>
    </file>
</modification>
