/
var
/
www
/
html
/
plugin-techloyce
/
Modules
/
Webstores
/
Repositories
/
Upload File
HOME
<?php namespace Modules\Webstores\Repositories; use Exception; use PHPShopify\ShopifySDK; class ShopifyRepository { public static $availableResources = [ 'Customers', 'CustomerAddresses', 'Products', 'Orders' ]; private $identifier; private $shopify; private $config; public function setIdentifier($identifier) { $this->identifier = $identifier; } public function setShopifyObject($config) { $config['AccessToken'] = $this->identifier->destination_access_token; $this->shopify = new ShopifySDK($config); } /** * Get list of all customers */ public function getCustomers($filters=[]) { try { // $customers = $this->shopify->Customer->get(); $customerResource = $this->shopify->Customer(); $pageParams = [ 'limit' => 200, ]; if(count(array_filter($filters)) > 0) { $pageParams = array_merge($pageParams,$filters); } $customers = []; do { $customersList = $customerResource->get($pageParams); $customers = array_merge($customers, $customersList); $pageParams = $customerResource->getNextPageParams(); } while($pageParams); return $customers; } catch(Exception $e) { return false; } } /** * Get list of all products */ public function getProducts($filters=[]) { try { // $customers = $this->shopify->Customer->get(); $productResource = $this->shopify->Product(); $pageParams = [ 'limit' => 200, ]; if(count(array_filter($filters)) > 0) { $pageParams = array_merge($pageParams,$filters); } $products = []; do { $productsList = $productResource->get($pageParams); $products = array_merge($products, $productsList); $pageParams = $productResource->getNextPageParams(); } while($pageParams); return $products; } catch(Exception $e) { return false; } } public function getOrders($filters=[]) { try { // $customers = $this->shopify->Customer->get(); $orderResource = $this->shopify->Order(); $pageParams = [ 'limit' => 200, ]; if(count(array_filter($filters)) > 0) { $pageParams = array_merge($pageParams,$filters); } $orders = []; do { $ordersList = $orderResource->get($pageParams); $orders = array_merge($orders, $ordersList); $pageParams = $orderResource->getNextPageParams(); } while($pageParams); return $orders; } catch(Exception $e) { return false; } } }