PHP code example of jorisros / data-compare
1. Go to this page and download the library: Download jorisros/data-compare 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/ */
jorisros / data-compare example snippets
$product = Product::getBySku($xmlProduct['sku']);
if (!$product) {
$product = new Product();
}
$dataproviderA = new \DataCompare\SimpleProvider();
$dataproviderA->addString('sku', $product->getSku());
$dataproviderA->addString('title', $product->getTitle());
$dataproviderA->addString('price', $product->getPrice());
$dataproviderB = new \DataCompare\SimpleProvider();
$dataproviderB->addString('sku', $jsonImport->sku);
$dataproviderB->addString('title', $jsonImport->title);
$dataproviderB->addString('price', $jsonImport->price);
$compareComponent = new \DataCompare\DataCompare($dataproviderA, $dataproviderB);
if (!$compareComponent->isTheSame()){
// If result is not equal update the product
$product->save()
}