Showing posts with label Pagination. Show all posts
Showing posts with label Pagination. Show all posts

Tuesday 24 September 2019

How to create pagination in shopify rest api using php

Shopify new API next page issue | page_info => invalid value

Shopify API version 2019-07 you do indeed need to use cursor-based pagination.

First make a normal API call, include the header response.

Then in the header response API, you will see the "link" parameter with rel next or previous.

Extract the page_info and then make another call with page_info.
The first API call is something like this:

https://.....@abc.myshopify.com/admin/api/2019-10/products.json?limit=2&published_status=published
To get header response from API response :
function getheaderarray($apiresponse){
       
        $data = explode("\n",$apiresponse);
        $headers['status'] = $data[0];
        array_shift($data);
        foreach($data as $part){
            $middle = explode(":",$part,2);
            if ( !isset($middle[1]) ) { $middle[1] = null; }
            $headers[trim($middle[0])] = trim($middle[1]);
        }
       
        return $headers;
  }  
Then the second API call is something like this:
https://.....@abc.myshopify.com/admin/api/2019-10/products.json?limit=2&page_info=abcdsf21asdf3afdfdfd1safd51s3f1x32ref4asdj
When you make the second call, do not add any filers as the filters will be applied from the first call.
FYI: if your testing in a browser due to the way the link is in angle brackets, it will be hidden, so just view source code in your developer environment.

Saturday 8 December 2018

How to log all | full SQL | Mysql queries in Magento 2

Show ALL | Full magento 2 query with Sorting, Pagination and Filter in Magento 2

Open : /var/www/html/magento/jaydip kansagra/app/etc/di.xml


Find 

<preference for="Magento\Framework\DB\LoggerInterface" 

Replace

<preference for="Magento\Framework\DB\LoggerInterface" type="Magento\Framework\DB\Logger\File"/>
 <type name="Magento\Framework\DB\Logger\File">
      <arguments>
          <argument name="logAllQueries" xsi:type="boolean">true</argument>
          <argument name="debugFile" xsi:type="string">log/sql.log</argument>
      </arguments>
 </type>


Open : /var/www/html/magento/frye-magento/var/log/sql.log

Thursday 3 May 2018

How to get the final sql / mysql query from the grid includes filters and pagination in Magento


Open Following file
Open MagentoRoot/lib/Varien/Db/Adapter/Pdo/Mysql.php
Update false to true
protected $_debug = true
protected $_logAllQueries  = true

Friday 28 April 2017

Pagination on shopify collection page with linklist

<h1 class="desktop-6 desktop-push-3 tablet-3 mobile-3">
  {% if collection.handle == 'all' %}{{ 'collections.general.all_products' | t }}
  {% elsif collection.handle == 'e-juice' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'a-d' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'e-i' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'j-m' %}
      E JUICE BRANDS
  {% elsif collection.handle == 'n-z' %}
      E JUICE BRANDS
  {% else %}
  {{ collection.title }}
  {% endif %}
</h1>



<div class="clear"></div>
{% if linklists[collection.handle].links.size > 0 %}

<div class="collsn_img_link">
    {% if collection.image %}
    <img src="{{ collection | img_url: 'master' }}"  alt="{{ collection.title | escape }}" />
    {% endif %}
  </div>

<div class="rte">
    {{ collection.description | remove: "[banner]" }}
  
  </div>
{% endif %}
{% if linklists[collection.handle].links.size > 0 %}

<div class="desktop-12 tablet-6 mobile-3 collecsn-linklist ">
  {% comment %}
   <p class="chose-categry">Choose a sub category:-</p>
  {% endcomment %}
      {% assign collections = linklists[collection.handle].links %}
    {% paginate collections by 40 %}
     {% assign currentpage = paginate.current_page %}
      {% assign current_offset = paginate.current_offset %}
    {% assign offset_limit = paginate.current_offset | plus:40 %}
  <ul id="myList" >
  {% for collection_link in collections %}
    {% assign forindex = forloop.index %}
    {% if current_offset < forindex and offset_limit >= forindex %}
    <li class="desktop-3 tablet-3 mobile-3 {% cycle ' first', '', '', ' last' %}">
      {% assign collection = collection_link.object %}
      {% if collection_link.type == 'collection_link' %}
      <div class="collection-image">
        <a href="{{ collection.url }}" title="{{ collection_title }}">
          {% if collection.image %}
          {{ collection.image.src | collection_img_url: 'large' | img_tag: collection_title }}
          {% else %}
          {{ collection.products.first.featured_image | product_img_url: 'large' | img_tag: collection_title }}
          {% endif %}
          <h3>{{ collection_link.title }}</h3>
        </a>    
      </div>
      {% else %}
        <div class="collection-info-inner">     
          <h3>{{ collection_link.title | link_to: collection_link.url }}</h3>
        </div>
      {% endif %}
<!--           <div class="collection-info-inner"> -->
<!--             <a href="{{ collection.url }}" title="{{ collection_title }} collection"> -->
<!--               <h3>{{ link.title | link_to: link.url }}</h3> -->
<!--             </a> -->
<!--        </div> -->
    </li>
    {% endif %}
    {% endfor %}
  </ul>
{% include 'pagination' %}
{% endpaginate %}
  <div class="clear"></div>
<!--   <div id="loadMore">See more</div> -->
  </div>
{% else %}
{% paginate collection.products by 40 %}
<!-- Start Sidebar -->
{% if settings.collection_sidebar %}
{% include 'collection-sidebar' %}
{% endif %}
<!-- End Sidebar -->


<div class="{% if settings.collection_sidebar %}desktop-9 tablet-6{% else %}desktop-12 tablet-6{% endif %} mobile-3">

  <div id="collection-description" class="desktop-12 tablet-6 mobile-3">

<div class="collsn_img">
    {% if collection.image and collection.handle != "candy"%}
    <img src="{{ collection | img_url: 'master' }}"  alt="{{ collection.title | escape }}" />
    {% endif %}
  </div>

<div class="rte" contenteditable="true" spellcheck="false">
    {{ collection.description | remove: "[banner]" }}
  
  </div>
</div>
  {% if settings.collection_sidebar == false %}
  {% if settings.filters %}
  <div id="full-width-filter" class="desktop-12 tablet-6 mobile-3">
    {% include 'filter' %}
  </div>
  {% endif %} 
  {% endif %}

 {% comment %} <div id="full-width-filter" class="desktop-12 tablet-6 mobile-3">
  {% include 'dropdown-filter' %}
  </div>  {% endcomment %}
  <div id="product-loop">
    <div id="product_collection">
    {% for product in collection.products %}
    {% assign products-per-row = settings.products-per-row %}
   
    <div id="product-listing-{{ product.id }}" class="product_price product-index {% if products-per-row == "6" %}desktop-2{% elsif products-per-row == "4" %}desktop-3{% elsif products-per-row == "3" %}desktop-4{% elsif products-per-row == "5" %}desktop-fifth{% elsif products-per-row == "2" %}desktop-6{% endif %} tablet-half mobile-half" data-alpha="{{ product.title }}" data-price="{{ product.price | money_without_currency }}">          
      {% include 'product-listing' %}
    </div>
    {% endfor %}
    </div>
  </div>
</div>
{% include 'pagination' %}
{% endpaginate %}

{% endif %}


<script>

 $( document ).ready(function() {
 
    (function($){
      function fixButtonHeights() {
        var heights = new Array();

        // Loop to get all element heights
        $('.product-index').each(function() {
         
          // Need to let sizes be whatever they want so no overflow on resize
          $(this).css('min-height', '0');
          $(this).css('max-height', 'none');
          $(this).css('height', 'auto');
         
          // Then add size (no units) to array
          heights.push($(this).height());
        
//         alert(heights);
        });

        // Find max height of all elements
        var max = Math.max.apply( Math, heights );
//         alert(max);

        // Set all heights to max height
        $('.product-index').each(function() {
        
          $(this).css('height', max + 'px');
          // Note: IF box-sizing is border-box, would need to manually add border
               

        });
      }

      $(window).load(function() {
        // Fix heights on page load
        setTimeout(function() {
        fixButtonHeights();
        }, 3000);
        // Fix heights on window resize
        $(window).resize(function() {
          // Needs to be a timeout function so it doesn't fire every ms of resize
          setTimeout(function() {
            fixButtonHeights();
          }, 100);
        });
      });
    })(jQuery);
     
  });
 
</script>
<style>
 
</style>
<script>

</script>
<!-- <script>
  $(document).ready(function () {
    size_li = $("#myList li").size();
    x=40;
    $('#myList li:lt('+x+')').show();
    $('#loadMore').click(function () {
        x= (x+40 <= size_li) ? x+40 : size_li;
      if(x == size_li || x >= size_li){
        $('#loadMore').hide();
      }
        $('#myList li:lt('+x+')').show();
    });
});
</script> -->

Friday 26 June 2015

Pagination in CodeIgniter

Controller:
------------------------
public function index() {
        $count = $this->dcategory->Count_drugcategories();
        $page = ($this->uri->segment(2)) ? $this->uri->segment(2) : 0;
        $this->load->library('pagination');
        $config['base_url'] = base_url('drug_categories');
        $config['use_page_numbers'] = TRUE;
        $config['total_rows'] = $count;
        $config['per_page'] = 10;
        $config["uri_segment"] = 2;
        $this->pagination->initialize($config);
        $limit = $config['per_page'];
        $start = ($page  == 0) ? 0 : ($page * $config['per_page']) - $config['per_page'];
        $data['query'] = $this->dcategory->Getlist_drugcategories($start,$limit);      
        $seo['title'] = 'Drug Categories List | ekimed';
        $data['links'] = $this->pagination->create_links();
        $this->load->view('layout/header',$seo);
        $this->load->view('drug_categories/listdrugcategories',$data);
        $this->load->view('layout/footer');
    }

Model:
----------------------
function Getlist_drugcategories($limit=0,$start=0){
        $this->db->select('*');
        if($limit>0 && $start>=0) {
            $this->db->limit($limit,$start);
        } else {
            $this->db->limit(10);
        }
        $query = $this->db->get($this->drugs_category);
        if($query->num_rows() > 0){
            return $query->result();
        } 
        return FALSE;
    }

Views:
-----------
<?php echo $links; ?>