Jump to content

ContextErrorException Notice: Undefined index: sort_selected


ZiedDams

Recommended Posts

Hello,  I was coding my custom listing products in a front controller, i got stack in the sort function this code is from my controller  :

    public function postProcess()

    {

        $this->setAuctionOrder();

        $this->setAuctionsData();

        if (Tools::isSubmit('from-xhr')) {

            $this->setOrdering();

        }

       parent::postProcess();

    }
    private function setAuctionOrder()
    {
        if ($order = Tools::getValue('order')) {
            $order = explode('.', $order);
            $this->orderBy = isset($order[1]) ? $order[1] : 'position';
            $this->orderWay = isset($order[2]) ? $order[2] : 'asc';
        } else {
            $this->orderBy = 'position';
            $this->orderWay = 'asc';
        }
    }
   private function setOrdering()
    {
      ob_end_clean();
      header('Content-Type: application/json');
      die(json_encode($this->getAjaxProductSearchVariables()));

    }
    private function getAjaxProductSearchVariables(){
      $this->setAuctionOrder();
      $sort_orders = $this->getAvailableSortOrders();
      $this->setAuctionsData();

      $page_link = $this->context->link->getModuleLink('auctionpremium', 'allauctions');
      $order_by = Tools::strtolower($this->orderBy);
      $order_way = Tools::strtolower($this->orderWay);
      $url = Tools::url($page_link, 'order=product.'.$order_by.'.'.$order_way);

      if ($this->p > 1) {
          $url = Tools::url($url, 'page='.$this->p);
      }

      $searchVariables = [
          'label' => $this->l('Auctions'),
          'sort_orders' => array('sort_orders' => $sort_orders),
          'pagination' => $this->getPagination(),
          'js_enabled' => true,
          'current_url' => $url,
          'rendered_products' =>
              $this->context->smarty->fetch(
                  $this->module->getLocalPath() . 'views/templates/front/AuctionsList.tpl'
              )
      ];

      return $searchVariables;
    }
    private function getAvailableSortOrders(){
      $page_link = $this->context->link->getModuleLink('auctionpremium', 'runningauctions');
      $order_by = Tools::strtolower($this->orderBy);
      $order_way = Tools::strtolower($this->orderWay);

      return [
          [
              'url' => Tools::url($page_link, 'order=product.position.asc'),
              'current' => $order_by == 'position' && $order_way == 'asc',
              'label' => $this->l('Relevance')
          ],
          [
              'url' => Tools::url($page_link, 'order=product.name.asc'),
              'current' => $order_by == 'name' && $order_way == 'asc',
              'label' => $this->l('Name, A to Z')
          ],
          [
              'url' => Tools::url($page_link, 'order=product.name.desc'),
              'current' => $order_by == 'name' && $order_way == 'desc',
              'label' => $this->l('Name, Z to A')
          ],
          [
              'url' => Tools::url($page_link, 'order=auction.end_time.asc'),
              'current' => $order_by == 'end_time' && $order_way == 'asc',
              'label' => $this->l('End time, near to far')
          ],
          [
              'url' => Tools::url($page_link, 'order=auction.end_time.desc'),
              'current' => $order_by == 'end_time' && $order_way == 'desc',
              'label' => $this->l('End time, far to near')
          ]
      ];
    }
    private function setAuctionsData()
    {
        $auctions_data = $this->getAuctionsData();
        $sort_orders = $this->getAvailableSortOrders();
        $this->context->smarty->assign(array("auctions" => $auctions_data, "sort_orders"=>array('sort_orders' => $sort_orders),"pagination" => $this->getPagination()));
    }

And this is a part of the Template

        <div class="products-select">
          <div class="col-md-6 hidden-sm-down total-products">
            {if $auctions|count > 1}
            <p>{l s='There are %s products.' mod='auctionpremium' sprintf=[$auctions|count]}</p>
            {else}
            <p>{l s='There is %s products.' mod='auctionpremium' sprintf=[$auctions|count]}</p>
            {/if}
          </div>
          <div class="col-md-6">
             {block name='sort_by'}
            {include file='catalog/_partials/sort-orders.tpl' listing=$sort_orders}
            {/block}
          </div>
        </div>

The problem is i got an error  with this message ContextErrorException Notice: Undefined index: sort_selected.

 

Any Help , And Thanks.

 

 

 

Link to comment
Share on other sites

  • 5 months later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...