PHP code example of promoqui / promoqui-api-php

1. Go to this page and download the library: Download promoqui/promoqui-api-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

promoqui / promoqui-api-php example snippets


namespace Crawlers;


Settings::$country = 'it';
Settings::$host = 'api.promotest.dev';
Settings::$app_secret = 'sup3rs3cr3t';
Settings::$schema = 'http'; // or https

$brand = Brand::find('Apple');

$brands = Brand::list();

$city = City::find('Rome');

$city = City::find_or_create('Rome');

$cities = array_filter(City->all(), function($val){return $val['country'] == 'gbr';}); # will return an array of City objects that havve only country=gbr

$store = Store::find('Via Roma, 32', '80100');
if ($store == null){
  $store = new Store();
  $store->$name = "Store name"; # Required!
  $store->$address = "Via Roma, 32"; # Required!
  $store->$city = "Naples"; # if the city is not present on database then the city will be created. Required!
  $store->$latitude = ""; # insert the store's latitude.
  $store->$longitude = "";# insert the store's longitude.
  $store->$zipcode = ""; # insert the store's postalcode. if there is no postalcode, insert "00000". Required!
  $store->$origin = ""; # insert the store's url. Required!
  $store->$phone = "";# insert the store's phone if present
}
$store->$opening_hours = [store_hours]; # Insert the store's opening hours as array. Required!
$store->save(); # Save store's data

>[["weekday"=>0, "open_am"=>"09:00", "close_am"=>"13:00", "open_pm"=>"14:00", "close_pm"=>"18:00"], ...]
> If the store is closed you need to use such as: [ ["weekday"=>6, "closed"=>true] ]
> The opening_hours must be in total 7 (one for every day) and must be uniq so please be carreful with this
>

$leaflet = Leaflet::find($url);
if ($leaflet == null) {
  $leaflet = new Leaflet();
  $leaflet->$name = 'Nice leaflet';
  $leaflet->$url = $url;
  $leaflet->$store_ids = [ $storeIds];
  $leaflet->save();
}

$leaflet = new Leaflet();
$leaflet->$url = $url; # Set to a significant URL to avoid repetitions
$leaflet->$name = "Nice leaflet";
$leaflet->$store_ids = [ $storeIds ];
$leaflet->$pdf_data = $binary_blob;
$leaflet->save();

$leaflet = new Leaflet();
$leaflet->$name = "leaflet's name";
$leaflet->$url = "leaflet's url";
$leaflet->$image_urls = [ leaflet_pages ]; # it must be an array of urls
$leaflet->$store_ids = [ storeIds ];
$leaflet->save();

foreach($offers as $data){
  $data["store_ids"] = $storeIds; #add store ids to offer array
  $offer = new Offer($data);
  $offer->save();
}



// Create DOM from URL or file
$html = file_get_html('http://www.google.com/');

// Find all images
foreach($html->find('img') as $element)
       echo $element->src . '<br>';

// Find all links
foreach($html->find('a') as $element)
       echo $element->href . '<br>';
bash
composer