particular single product's price, title and other detail fetch using flipkart api

is single product page woocommerce
woocommerce custom template for single product
single product page template
creating custom single product woocommerce templates
woocommerce single-product template override
woocommerce single product description
wordpress single post template for specific category
woocommerce/single-product template for category

I am using clusterdev.flipkart-api and from this api i got flipkart directory name and link then click on it i am getting directory's available products. But i need to fetch particular product's price, title, inStock details from this api. i had try to make some changes but i don't have more knowledge in json so i am not able to get details. After getting particular product's price, title, inStock details then i need to update it into the my database.

Flipkart Api FAQ Link: http://www.flipkart.com/affiliate/apifaq

Please suggest me what changes i need to make to get product's price, title, instock and other details.

Actual Code: https://github.com/xaneem/flipkart-api-php Included File: https://github.com/xaneem/flipkart-api-php/blob/master/clusterdev.flipkart-api.php

Code here

<?php

//Include the class.
include "clusterdev.flipkart-api.php";

//Replace <affiliate-id> and <access-token> with the correct values
$flipkart = new \clusterdev\Flipkart("pratikson3", "853d3bc027514b3aa33f1caa4f30f1cf", "json");


//To view category pages, API URL is passed as query string.
$url = isset($_GET['url'])?$_GET['url']:false;
if($url){
//URL is base64 encoded to prevent errors in some server setups.
$url = base64_decode($url);

//This parameter lets users allow out-of-stock items to be displayed.
$hidden = isset($_GET['hidden'])?false:true;

//Call the API using the URL.
$details = $flipkart->call_url($url);

if(!$details){
    echo 'Error: Could not retrieve products list.';
    exit();
}

//The response is expected to be JSON. Decode it into associative arrays.
$details = json_decode($details, TRUE);

//The response is expected to contain these values.
$nextUrl = $details['nextUrl'];
$validTill = $details['validTill'];
$products = $details['productInfoList'];

//Products table
echo "<table border=2 cellpadding=10 cellspacing=1 style='text-align:center'>";
$count = 0;
$end = 1;

//Make sure there are products in the list.
if(count($products) > 0){
    foreach ($products as $product) {

        //Hide out-of-stock items unless requested.
        $inStock = $product['productBaseInfo']['productAttributes']['inStock'];
        if(!$inStock && $hidden)
            continue;

        //Keep count.
        $count++;

        //The API returns these values nested inside the array.
        //Only image, price, url and title are used in this demo
        $productId = $product['productBaseInfo']['productIdentifier']['productId'];
        $title = $product['productBaseInfo']['productAttributes']['title'];
        $productDescription = $product['productBaseInfo']['productAttributes']['productDescription'];

        //We take the 200x200 image, there are other sizes too.
        $productImage = array_key_exists('200x200', $product['productBaseInfo']['productAttributes']['imageUrls'])?$product['productBaseInfo']['productAttributes']['imageUrls']['200x200']:'';
        $sellingPrice = $product['productBaseInfo']['productAttributes']['sellingPrice']['amount'];
        $productUrl = $product['productBaseInfo']['productAttributes']['productUrl'];
        $productBrand = $product['productBaseInfo']['productAttributes']['productBrand'];
        $color = $product['productBaseInfo']['productAttributes']['color'];
        $productUrl = $product['productBaseInfo']['productAttributes']['productUrl'];

        //Setting up the table rows/columns for a 3x3 view.
        $end = 0;
        if($count%3==1)
            echo '<tr><td>';
        else if($count%3==2)
            echo '</td><td>';
        else{
            echo '</td><td>';
            $end =1;
        }

        echo '<a target="_blank" href="'.$productUrl.'"><img src="'.$productImage.'"/><br>'.$title."</a><br>Rs. ".$sellingPrice;

        if($end)
            echo '</td></tr>';

    }
}

//A message if no products are printed. 
if($count==0){
    echo '<tr><td>The retrieved products are not in stock. Try the Next button or another category.</td><tr>';
}

//A hack to make sure the tags are closed.  
if($end!=1)
    echo '</td></tr>';

echo '</table>';

//Next URL link at the bottom.
echo '<h2><a href="?url='.base64_encode($nextUrl).'">NEXT >></a></h2>';

//That's all we need for the category view.
exit();
}



//Category Selection Page
//If the control reaches here, the API directory view is shown.

//Query the API
$home = $flipkart->api_home();

//Make sure there is a response.
if($home==false){
    echo 'Error: Could not retrieve API homepage';
    exit();
}

//Convert into associative arrays.
$home = json_decode($home, TRUE);

$list = $home['apiGroups']['affiliate']['apiListings'];

//Create the tabulated view for different categories.
echo '<table border=2 style="text-align:center;">';
$count = 0;
$end = 1;
foreach ($list as $key => $data) {
    $count++;
    $end = 0;

    //To build a 3x3 table.
    if($count%3==1)
        echo '<tr><td>';
    else if($count%3==2)
        echo '</td><td>';
else{
    echo '</td><td>';
    $end =1;
}

echo "<strong>".$key."</strong>";
echo "<br>";
//URL is base64 encoded when sent in query string.
echo '<a href="?url='.base64_encode($data['availableVariants']['v0.1.0']['get']).'">View Products &raquo;</a>';
}

if($end!=1)
    echo '</td></tr>';
echo '</table>';

//This was just a rough example created in limited time.
//Good luck with the API.
<?php

    //Include the class.

    include "clusterdev.flipkart-api.php";

    //Replace <affiliate-id> and <access-token> with the correct values

    $flipkart = new \clusterdev\Flipkart("pratikson3", "853d3bc027514b3aa33f1caa4f30f1cf", "json");

    $pid = "Flipkart Product ID";

    $url = 'https://affiliate-api.flipkart.net/affiliate/product/json?id=' .$pid;

    //Call the API using the URL.

    $details = $flipkart->call_url($url);

    if(!$details){

        echo 'Error: Could not retrieve products list.';

        exit();
    }

    //The response is expected to be JSON. Decode it into associative arrays.

    $details = json_decode($details, TRUE);

    $price = $details['productBaseInfo']['productAttributes']['sellingPrice']['amount'];

    $inStock = (int) $details['productBaseInfo']['productAttributes']['inStock'];

    $title = $details['productBaseInfo']['productAttributes']['title'];

    $description = $details['productBaseInfo']['productAttributes']['productDescription'];

How to check if the product is in a certain category on a single , I don't think get_categories() is the best option for you in this case because it returns a string with all the categories listed as anchor tags, fine for displaying, but� 1988 Bunnahabhain 30 Year Old "Old Particular" K&L Exclusive Single Refill Hogshead Cask Strength Single Malt Scotch Whisky (750ml) SKU #1430016. Bunnahabhain has been doing its thing since 1881 with just a short shutdown in the early 1980s.

Try this,

<?php

$newStr = 'hairpin'; // Your search query
$url = 'https://affiliate-api.flipkart.net/affiliate/search/json?query='.$newStr.'&resultCount=1';

$pid = "COMEAE7XDPMSAMRW"; // Provide our product ID here
$urlNew = 'https://affiliate-api.flipkart.net/affiliate/product/json?id=' .$pid;

        //The headers are required for authentication
        $headers = array(
                'Cache-Control: no-cache',
                'Fk-Affiliate-Id: '.'xxxxxx',// Your flipcart affilicate ID
                'Fk-Affiliate-Token: '.'231324rf3r3434f'// your affiliate token
        );

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
        curl_setopt($ch, CURLOPT_USERAGENT, 'PHP-ClusterDev-Flipkart/0.1');
        curl_setopt($ch, CURLOPT_TIMEOUT, 30);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
        $result = curl_exec($ch);
        curl_close($ch);        
        $json = json_decode($result);       
        $allResults = $json->productInfoList;

    var_dump($allResults[0]->productBaseInfo->productAttributes);

This worked for me, it provides the below response.

object(stdClass)[7]
  public 'title' => string 'I Jewels Pearl With Jhumka Hair Pin' (length=35)
  public 'productDescription' => string 'I Jewels Traditional Gold Plated Elegantly Handcrafted Pearl with Jhumka Hair Pin for Women T1013W (White)' (length=106)
  public 'imageUrls' => 
    object(stdClass)[8]
      public '200x200' => string 'http://img.fkcdn.com/image/hair-accessory/s/n/h/t1013w-1-i-jewels-pearl-with-jhumka-200x200-imaeevhbgq9yjuxy.jpeg' (length=113)
      public '400x400' => string 'http://img.fkcdn.com/image/hair-accessory/s/n/h/t1013w-1-i-jewels-pearl-with-jhumka-400x400-imaeevhbgq9yjuxy.jpeg' (length=113)
      public '800x800' => string 'http://img.fkcdn.com/image/hair-accessory/s/n/h/t1013w-1-i-jewels-pearl-with-jhumka-800x800-imaeevhbgq9yjuxy.jpeg' (length=113)
      public 'unknown' => string 'http://img.fkcdn.com/image/hair-accessory/s/n/h/t1013w-1-i-jewels-pearl-with-jhumka-original-imaeevhbgq9yjuxy.jpeg' (length=114)
  public 'maximumRetailPrice' => 
    object(stdClass)[9]
      public 'amount' => float 1100
      public 'currency' => string 'INR' (length=3)
  public 'sellingPrice' => 
    object(stdClass)[10]
      public 'amount' => float 399
      public 'currency' => string 'INR' (length=3)
  public 'productUrl' => string 'http://dl.flipkart.com/dl/jewels-pearl-jhumka-hair-pin/p/itmeevzzwhmvbksy?pid=HACEEVZZHNVMRSNH&affid=sukeshini' (length=110)
  public 'productBrand' => string 'I Jewels' (length=8)
  public 'inStock' => boolean true
  public 'isAvailable' => boolean true
  public 'codAvailable' => boolean true
  public 'emiAvailable' => null
  public 'discountPercentage' => float 63
  public 'cashBack' => null
  public 'offers' => 
    array (size=0)
      empty
  public 'size' => null
  public 'color' => string '' (length=0)
  public 'sizeUnit' => string '' (length=0)
  public 'sizeVariants' => string '[HACEEVZZHNVMRSNH]' (length=18)
  public 'colorVariants' => string '[]' (length=2)
  public 'styleCode' => null

Hope this helps.

certain product are single product in cart woocommerce, Instead of woocommerce_add_cart_item_data you can use woocommerce_add_to_cart_validation . this works. add_filter(� [This thread is closed.] Hi there, i would like to have a different single product page template loaded for products in a particular category (domain.…

Try this,

Search API - https://affiliate-api.flipkart.net/affiliate/1.0/search.json?query=laptop

product Api - https://affiliate-api.flipkart.net/affiliate/1.0/product.json?id=MOBFK4REY6GGXSAY

https://www.makemyshop.in/

How to Create a Single Product Website With WordPress (In 4 Steps), In theory, you can build a website around any kind of item. However, single product stores tend to work better in specific situations, such as:. Particular definition, of or relating to a single or specific person, thing, group, class, occasion, etc., rather than to others or all; special rather than general: one's particular interests in books.

Custom single product page template for specific category? � Issue , Hey there, How to call a custom single product page template if products are within a specific category? I want:� I will add an if condition that checks whether a product belongs to a particular category and then load the related single-product.php in the custom template. Now, there is no real need to rename

WooCommerce: How to Assign Free Shipping to a Single Product?, “Product Count”). Assigning a shipping class to a WooCommerce product How to set up a Flat Rate to enable per-product shipping. That's it. what if I need to set the free shipping over a certain amount, for a specific shipping class only? Many businesses offer a range of product lines which may be unique to a single organization or may be common across the business's industry. In 2002 the US Census compiled revenue figures for the finance and insurance industry by various product lines such as "accident, health and medical insurance premiums" and "income from secured consumer

WooCommerce Single Product Page Hooks: Visual Guide, These are ways to make the shortcode more specific. The [products] shortcode is one of our most robust shortcodes, which can replace various other strings used in Display the URL on the add to cart button of a single product by ID. Args: The Government of India (GoI) appears to be giving an impetus to foreign investment in single brand product retail trading (SBRT). In July 2015, the GoI clarified that non-resident entities can undertake SBRT in India through one or more wholly owned subsidiaries or joint ventures.

Comments
  • I tried to make changes but nothing happens, i am new in json, i don't know how to made changes in given above query. Can you please suggest me what changes i need to made.
  • No need to change anything in clusterdev.flipkart-api.php,just make changes in demo.php/any test file to make call to API.I have edited my code to understand.
  • Thanks i will try it. And let you know.