<?php

/**
 * Script to turn on related products for ALL products
 * @author Robert Mullins <*****@*****.**>
 * @license The MIT License (MIT)
 */
require 'bigcommerce.php';
use Bigcommerce\Api\Client as Bigcommerce;
/* API Connection */
Bigcommerce::configure(array('store_url' => 'https://store-********.mybigcommerce.com', 'username' => '*******', 'api_key' => '***********************'));
Bigcommerce::verifyPeer(false);
Bigcommerce::setCipher('RC4-SHA');
$num_of_products = Bigcommerce::getProductsCount();
if ($num_of_products <= 250) {
    $max_pages = 1;
} else {
    $pages_double = $num_of_products / 250;
    $pages_int = (int) ($num_of_products / 250);
    if ($pages_double > $pages_int) {
        $max_pages = $pages_int + 1;
    } else {
        $max_pages = $pages_int;
        //If 250 goes into number of products evenly (rare)
    }
}
$fields = array('related_products' => '-1');
$processed = array();
//Collection returns duplicates sometimes, this will hold the ID of all products we processed.
$current_page = 1;
while ($current_page <= $max_pages) {