Compare Proposal

Nothing to compare.

I need custom parsing scripts made for affiliate egg plugin wordpress

  • Posted at : 1 month ago
  • Post Similar Project
30

Budget
3
Proposals
122
Views
Expired
Status
Skills Required

Posted By -

ZZ

USA
0.0
Projects Posted : 1
Projects Paid : 0
Services Purchased : 0
Total Spent :
0
Feedbacks : 0 %

Project Details show (+) hide (-)

Please send proposal only if you can do this job. Will pay per parsing script. 3 to start with then an additional 20 more if I'm satisfied with the work.
The Plugin work is to parse the details of products and fetch them to wordpress php and xpath skills are required for this.
Refer this link: 

You must add information in the header,an example
/*
URI: 

SEARCH URI: 

*
*/
Each class-parser must have next methods
parseCatalog();
parseTitle();
parseDescription();
parsePrice();
parseImg();
parseImgLarge();
parseOldPrice();
parseManufacturer();
parseExtra();
isInStock();
If you need to parse any additional data, use methods parseExtra().
I also need reviews: comments & rating score parsed


The Affiliate Egg Plugin will integrate with their Content Egg Plugin which will be used to test if the custom parser is working correctly: More info Here: 

https://ce-docs.keywordrush.com/integrations/affiliateeggintegration


Fipkart.com example script:

<?php

namespace Keywordrush\AffiliateEgg;

/**
 * FlipkartcomParser class file
 *
 * @author keywordrush.com [removed] @link http://www.keywordrush.com/
 * @copyright Copyright &copy; 2018 keywordrush.com
 */
class FlipkartcomParser extends LdShopParser {

    protected $charset = 'utf-8';
    protected $currency = 'INR';

    public function parseCatalog($max)
    {
        return $this->xpathArray(".//a[@target='_blank' and @rel='noopener noreferrer'][1]/@href");
    }

    public function parseTitle()
    {
        if ($p = parent::parseTitle())
            return $p;
        return $this->xpathScalar(array(".//h1/span[2]", ".//h1/span"));
    }

    public function parseDescription()
    {
        $d = $this->xpathScalar(".//div/span[normalize-space(text())='Description']/../..//div/p");
        if (!$d)
            $d = $this->xpathScalar(".//div[normalize-space(text())='Description']/../div/div");
        if (!$d)
            $d = $this->xpathScalar(".//div[normalize-space(text())='Product Description']/../div[2]");
        return $d;
    }

    public function parsePrice()
    {
        if ($price = parent::parsePrice())
            return $price;

        $html = $this->dom->saveHTML();
        if (preg_match('/"price":(\d+?),/', $html, $mathces))
            return $mathces[1];

        if (preg_match('/"currency":"INR","decimalValue":"(.+?)",/', $html, $mathces))
            return $mathces[1];
    }

    public function parseOldPrice()
    {
        $html = $this->dom->saveHTML();
        if (preg_match('/"strikeOff":true,"value":(\d+?)}/', $html, $mathces))
            return $mathces[1];
    }

    public function parseImg()
    {
        if ($p = parent::parseImg())
        {
            $p = str_replace('http://rukmini1.flixcart.com', 'https://rukminim1.flixcart.com', $p);
            return str_replace('/image/128/128/', '/image/416/416/', $p);
        }
        if ($style = $this->xpathScalar(".//ul[@style]/li[@style]/div/div/@style"))
        {
            if (preg_match('/\((.+?)\)/', $style, $matches))
                return str_replace('/128/128/', '/416/416/', $matches[1]);
        }
    }

    public function parseExtra()
    {
        $extra = parent::parseExtra();

        $names = $this->xpathArray(".//div[normalize-space(text())='Specifications']/..//table//td[contains(@class, 'col-3-12') and position() = 1]");
        $values = $this->xpathArray(".//div[normalize-space(text())='Specifications']/..//table//td[2]");
        $feature = array();
        for ($i = 0; $i < count($names); $i++)
        {
            if (!empty($values[$i]))
            {
                $feature['name'] = sanitize_text_field($names[$i]);
                $feature['value'] = sanitize_text_field($values[$i]);
                $extra['features'][] = $feature;
            }
        }

        $extra['rating'] = TextHelper::ratingPrepare($this->xpathScalar(".//*[contains(@id, 'productRating')]"));
        $extra['ratingDecimal'] = (float) $this->xpathScalar(".//*[contains(@id, 'productRating')]");
        $extra['ratingCount'] = 0;
        $extra['reviewUrl'] = '';
        if ($extra['rating'])
        {
            $html = $this->dom->saveHTML();
            if (preg_match('/<span>.+?([0-9,]+)\sReviews<\/span>/', $html, $matches))
                $extra['ratingCount'] = (int) str_replace(',', '', $matches[1]);

            $extra['reviewUrl'] = str_replace('/p/', '/product-reviews/', $this->getUrl());

            if (preg_match('/<span>([0-9,]+)\sRatings.+?<\/span>/', $html, $matches))
                $extra['ratingCount2'] = (int) str_replace(',', '', $matches[1]);
        }

        return $extra;
    }

    public function isInStock()
    {
        if (!parent::isInStock())
            return false;

        $stock = $this->xpathScalar(".//div[contains(@class, 'col-12-12') and @style='padding:24px 0px 0px 0px']/div");
        if ($stock == 'Coming Soon')
            return false;

        return true;
    }

}