Primo Committ

This commit is contained in:
paoloar77
2024-05-07 12:17:25 +02:00
commit e73d0e5113
7204 changed files with 884387 additions and 0 deletions

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Attribute extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Attribute';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Category extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Category';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Coupon extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Coupon';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Customer extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Customer';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Note extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Note';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Order extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Order';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class PaymentGateway extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\PaymentGateway';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Product extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Product';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Query extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Query';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Refund extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Refund';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Report extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Report';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Review extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Review';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Setting extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Setting';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class ShippingMethod extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\ShippingMethod';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class ShippingZone extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\ShippingZone';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class ShippingZoneMethod extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\ShippingZoneMethod';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class System extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\System';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Tag extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Tag';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Tax extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Tax';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class TaxClass extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\TaxClass';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Term extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Term';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Variation extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Variation';
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Illuminate\Support\Facades\Facade;
class Webhook extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\WooCommerce\Models\Webhook';
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace Codexshaper\WooCommerce\Facades;
use Codexshaper\WooCommerce\WooCommerceApi;
use Illuminate\Support\Facades\Facade;
class WooCommerce extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return WooCommerceApi::class;
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Codexshaper\Woocommerce\Facades;
use Illuminate\Support\Facades\Facade;
class WoocommerceFacade extends Facade
{
/**
* Get the registered name of the component.
*
* @return string
*/
protected static function getFacadeAccessor()
{
return 'Codexshaper\Woocommerce\WooCommerceApi';
}
}

View File

@@ -0,0 +1,106 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Attribute extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'products/attributes';
/**
* Retrieve all Items.
*
* @param int $attribute_id
* @param array $options
*
* @return array
*/
protected function getTerms($attribute_id, $options = [])
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->all($options);
}
/**
* Retrieve single Item.
*
* @param int $attribute_id
* @param int $term_id
* @param array $options
*
* @return object
*/
protected function getTerm($attribute_id, $term_id, $options = [])
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->find($term_id, $options);
}
/**
* Create new Item.
*
* @param int $attribute_id
* @param array $data
*
* @return object
*/
protected function addTerm($attribute_id, $data)
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->create($data);
}
/**
* Update Existing Item.
*
* @param int $attribute_id
* @param int $term_id
* @param array $data
*
* @return object
*/
protected function updateTerm($attribute_id, $term_id, $data)
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->update($term_id, $data);
}
/**
* Destroy Item.
*
* @param int $attribute_id
* @param int $term_id
* @param array $options
*
* @return object
*/
protected function deleteTerm($attribute_id, $term_id, $options = [])
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->delete($term_id, $options);
}
/**
* Batch Update.
*
* @param int $attribute_id
* @param array $data
*
* @return object
*/
protected function batchTerm($attribute_id, $data)
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->batch($data);
}
}

View File

@@ -0,0 +1,52 @@
<?php
namespace Codexshaper\WooCommerce\Models;
class BaseModel
{
protected $properties = [];
/**
* Get Inaccessible Property.
*
* @param string $name
*
* @return int|string|array|object|null
*/
public function __get($name)
{
return $this->$name;
}
/**
* Set Option.
*
* @param string $name
* @param string $value
*
* @return void
*/
public function __set($name, $value)
{
$this->properties[$name] = $value;
}
public function __call($method, $parameters)
{
if (!method_exists($this, $method)) {
preg_match_all('/((?:^|[A-Z])[a-z]+)/', $method, $partials);
$method = array_shift($partials[0]);
if (!method_exists($this, $method)) {
throw new \Exception('Sorry! you are calling wrong method');
}
array_unshift($parameters, strtolower(implode('_', $partials[0])));
}
return $this->$method(...$parameters);
}
public static function __callStatic($method, $parameters)
{
return (new static())->$method(...$parameters);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Category extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'products/categories';
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Coupon extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'coupons';
}

View File

@@ -0,0 +1,27 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Customer extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'customers';
/**
* Download.
*
* @param int $id
*
* @return object
*/
protected function downloads($id, $options = [])
{
return Query::init()
->setEndpoint("customers/{$id}/downloads")
->all($options);
}
}

View File

@@ -0,0 +1,125 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Note extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint;
/**
* Retrieve all Items.
*
* @param int $order_id
* @param array $options
*
* @return array
*/
protected function all($order_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->all($options);
}
/**
* Retrieve single Item.
*
* @param int $order_id
* @param int $note_id
* @param array $options
*
* @return object
*/
protected function find($order_id, $note_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->find($note_id, $options);
}
/**
* Create new Item.
*
* @param int $order_id
* @param array $data
*
* @return object
*/
protected function create($order_id, $data)
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->create($data);
}
/**
* Destroy Item.
*
* @param int $order_id
* @param int $note_id
* @param array $options
*
* @return object
*/
protected function delete($order_id, $note_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->delete($note_id, $options);
}
/**
* Paginate results.
*
*
* @param int $order_id
* @param int $per_page
* @param int $current_page
* @param array $options
*
* @return array
*/
protected function paginate(
$order_id,
$per_page = 10,
$current_page = 1,
$options = []
) {
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->paginate($per_page, $current_page, $options);
}
/**
* Count all results.
*
* @param int $order_id
*
* @return int
*/
protected function count($order_id)
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->count();
}
/**
* Store data.
*
* @param int $order_id
*
* @return array
*/
public function save($order_id)
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->save();
}
}

View File

@@ -0,0 +1,137 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Order extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'orders';
/**
* Retrieve all notes.
*
* @param int $order_id
* @param array $options
*
* @return array
*/
protected function notes($order_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->all($options);
}
/**
* Retreive a note.
*
* @param int $order_id
* @param int $note_id
* @param array $options
*
* @return object
*/
protected function note($order_id, $note_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->find($note_id, $options);
}
/**
* Create a note.
*
* @param int $order_id
* @param array $data
*
* @return object
*/
protected function createNote($order_id, $data = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->create($data);
}
/**
* Delete a note.
*
* @param int $order_id
* @param int $note_id
* @param array $options
*
* @return object
*/
protected function deleteNote($order_id, $note_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/notes")
->delete($note_id, $options);
}
/**
* Retrieve all refunds.
*
* @param int $order_id
* @param array $options
*
* @return array
*/
protected function refunds($order_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->all($options);
}
/**
* Retrieve a refund.
*
* @param int $order_id
* @param int $refund_id
* @param array $options
*
* @return object
*/
protected function refund($order_id, $refund_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->find($refund_id, $options);
}
/**
* Create refund.
*
* @param int $order_id
* @param array $data
*
* @return object
*/
protected function createRefund($order_id, $data = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->create($data);
}
/**
* Delete refund.
*
* @param int $order_id
* @param int $refund_id
* @param array $options
*
* @return object
*/
protected function deleteRefund($order_id, $refund_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->delete($refund_id, $options);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class PaymentGateway extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'payment_gateways';
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Product extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'products';
}

View File

@@ -0,0 +1,124 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Refund extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint;
/**
* Retrieve all Items.
*
* @param int $order_id
* @param array $options
*
* @return array
*/
protected function all($order_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->all($options);
}
/**
* Retrieve single Item.
*
* @param int $order_id
* @param int $refund_id
* @param array $options
*
* @return object
*/
protected function find($order_id, $refund_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->find($refund_id, $options);
}
/**
* Create new Item.
*
* @param int $order_id
* @param array $data
*
* @return object
*/
protected function create($order_id, $data)
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->create($data);
}
/**
* Destroy Item.
*
* @param int $order_id
* @param int $refund_id
* @param array $options
*
* @return object
*/
protected function delete($order_id, $refund_id, $options = [])
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->delete($refund_id, $options);
}
/**
* Paginate results.
*
* @param int $order_id
* @param int $per_page
* @param int $current_page
* @param array $options
*
* @return array
*/
protected function paginate(
$order_id,
$per_page = 10,
$current_page = 1,
$options = []
) {
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->paginate($per_page, $current_page, $options);
}
/**
* Count all results.
*
* @param int $order_id
*
* @return int
*/
protected function count($order_id)
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->count();
}
/**
* Store data.
*
* @param int $order_id
*
* @return array
*/
public function save($order_id)
{
return Query::init()
->setEndpoint("orders/{$order_id}/refunds")
->save();
}
}

View File

@@ -0,0 +1,111 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Report extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'reports';
/**
* Retrieve all sales.
*
* @param array $options
*
* @return array
*/
protected function sales($options = [])
{
return Query::init()
->setEndpoint('reports/sales')
->all($options);
}
/**
* Retrieve all top sellers.
*
* @param array $options
*
* @return array
*/
protected function topSellers($options = [])
{
return Query::init()
->setEndpoint('reports/top_sellers')
->all($options);
}
/**
* Retrieve all coupons.
*
* @param array $options
*
* @return array
*/
protected function coupons($options = [])
{
return Query::init()
->setEndpoint('reports/coupons/totals')
->all($options);
}
/**
* Retrieve all customers.
*
* @param array $options
*
* @return array
*/
protected function customers($options = [])
{
return Query::init()
->setEndpoint('reports/customers/totals')
->all($options);
}
/**
* Retrieve all orders.
*
* @param array $options
*
* @return array
*/
protected function orders($options = [])
{
return Query::init()
->setEndpoint('reports/orders/totals')
->all($options);
}
/**
* Retrieve all products.
*
* @param array $options
*
* @return array
*/
protected function products($options = [])
{
return Query::init()
->setEndpoint('reports/products/totals')
->all($options);
}
/**
* Retrieve all reviews.
*
* @param array $options
*
* @return array
*/
protected function reviews($options = [])
{
return Query::init()
->setEndpoint('reports/reviews/totals')
->all($options);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Review extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'products/reviews';
}

View File

@@ -0,0 +1,74 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Setting extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'settings';
/**
* Retrieve option.
*
* @param int $group_id
* @param int $id
* @param array $options
*
* @return array
*/
protected function option($group_id, $id, $options = [])
{
return Query::init()
->setEndpoint("settings/{$group_id}")
->find($id, $options);
}
/**
* Retrieve options.
*
* @param int $id
* @param array $options
*
* @return array
*/
protected function options($id, $options = [])
{
return Query::init()
->setEndpoint('settings')
->find($id, $options);
}
/**
* Update Existing Item.
*
* @param int $group_id
* @param int $id
* @param array $data
*
* @return object
*/
protected function update($group_id, $id, $data)
{
return Query::init()
->setEndpoint("settings/{$group_id}")
->update($id, $data);
}
/**
* Batch Update.
*
* @param array $data
*
* @return object
*/
protected function batch($id, $data)
{
return Query::init()
->setEndpoint("settings/{$id}")
->batch($data);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class ShippingMethod extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'shipping_methods';
}

View File

@@ -0,0 +1,120 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Facades\WooCommerce;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class ShippingZone extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'shipping/zones';
/**
* Retrieve all Items.
*
* @param int $id
* @param array $options
*
* @return array
*/
protected function getLocations($id, $options = [])
{
return Query::init()
->setEndpoint("shipping/zones/{$id}/locations")
->all($options);
}
/**
* Update Existing Item.
*
* @param int $id
* @param array $data
*
* @return object
*/
protected function updateLocations($id, $data = [])
{
return WooCommerce::update("shipping/zones/{$id}/locations", $data);
}
/**
* Create new Item.
*
* @param int $id
* @param array $data
*
* @return object
*/
protected function addShippingZoneMethod($id, $data)
{
return Query::init()
->setEndpoint("shipping/zones/{$id}/methods")
->create($data);
}
/**
* Retrieve single Item.
*
* @param int $zone_id
* @param int $id
* @param array $options
*
* @return object
*/
protected function getShippingZoneMethod($zone_id, $id, $options = [])
{
return Query::init()
->setEndpoint("shipping/zones/{$zone_id}/methods")
->find($id, $options);
}
/**
* Retrieve all Items.
*
* @param int $id
* @param array $options
*
* @return array
*/
protected function getShippingZoneMethods($id, $options = [])
{
return Query::init()
->setEndpoint("shipping/zones/{$id}/methods")
->all($options);
}
/**
* Update Existing Item.
*
* @param int $zone_id
* @param int $id
* @param array $data
*
* @return object
*/
protected function updateShippingZoneMethod($zone_id, $id, $data = [])
{
return Query::init()
->setEndpoint("shipping/zones/{$zone_id}/methods")
->update($id, $data);
}
/**
* Destroy Item.
*
* @param int $zone_id
* @param int $id
* @param array $options
*
* @return object
*/
protected function deleteShippingZoneMethod($zone_id, $id, $options = [])
{
return Query::init()
->setEndpoint("shipping/zones/{$zone_id}/methods")
->delete($id, $options);
}
}

View File

@@ -0,0 +1,71 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class System extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint;
/**
* Retrieve all Items.
*
* @param array $options
*
* @return array
*/
protected function status($options = [])
{
return Query::init()
->setEndpoint('system_status')
->all($options);
}
/**
* Retrieve single tool.
*
* @param int $id
* @param array $options
*
* @return object
*/
protected function tool($id, $options = [])
{
return Query::init()
->setEndpoint('system_status/tools')
->find($id, $options);
}
/**
* Retrieve all tools.
*
* @param array $options
*
* @return array
*/
protected function tools($options = [])
{
return Query::init()
->setEndpoint('system_status/tools')
->all($options);
}
/**
* Run tool.
*
* @param int $id
* @param array $data
*
* @return object
*/
protected function run($id, $data)
{
return Query::init()
->setEndpoint('system_status/tools')
->update($id, $data);
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Tag extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'products/tags';
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Tax extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'taxes';
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class TaxClass extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'taxes/classes';
}

View File

@@ -0,0 +1,155 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Term extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint;
/**
* Retrieve all Items.
*
* @param int $attribute_id
* @param array $options
*
* @return array
*/
protected function all($attribute_id, $options = [])
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->all($options);
}
/**
* Retrieve single Item.
*
* @param int $attribute_id
* @param int $id
* @param array $options
*
* @return object
*/
protected function find($attribute_id, $id, $options = [])
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->find($id, $options);
}
/**
* Create new Item.
*
* @param int $attribute_id
* @param array $data
*
* @return object
*/
protected function create($attribute_id, $data)
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->create($data);
}
/**
* Update Existing Item.
*
* @param int $attribute_id
* @param int $id
* @param array $data
*
* @return object
*/
protected function update($attribute_id, $id, $data)
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->update($id, $data);
}
/**
* Destroy Item.
*
* @param int $attribute_id
* @param int $id
* @param array $options
*
* @return object
*/
protected function delete($attribute_id, $id, $options = [])
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->delete($id, $options);
}
/**
* Batch Update.
*
* @param int $attribute_id
* @param array $data
*
* @return object
*/
protected function batch($attribute_id, $data)
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->batch($data);
}
/**
* Paginate results.
*
* @param int $attribute_id
* @param int $per_page
* @param int $current_page
* @param array $options
*
* @return array
*/
protected function paginate(
$attribute_id,
$per_page = 10,
$current_page = 1,
$options = []
) {
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->paginate($per_page, $current_page, $options);
}
/**
* Count all results.
*
* @param int $attribute_id
*
* @return int
*/
protected function count($attribute_id)
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->count();
}
/**
* Store data.
*
* @param int $attribute_id
*
* @return array
*/
public function save($attribute_id)
{
return Query::init()
->setEndpoint("products/attributes/{$attribute_id}/terms")
->save();
}
}

View File

@@ -0,0 +1,155 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Facades\Query;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Variation extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint;
/**
* Retrieve all Items.
*
* @param int $product_id
* @param array $options
*
* @return array
*/
protected function all($product_id, $options = [])
{
return Query::init()
->setEndpoint("products/{$product_id}/variations")
->all($options);
}
/**
* Retrieve single Item.
*
* @param int $product_id
* @param int $id
* @param array $options
*
* @return object
*/
protected function find($product_id, $id, $options = [])
{
return Query::init()
->setEndpoint("products/{$product_id}/variations")
->find($id, $options);
}
/**
* Create new Item.
*
* @param int $product_id
* @param array $data
*
* @return object
*/
protected function create($product_id, $data)
{
return Query::init()
->setEndpoint("products/{$product_id}/variations")
->create($data);
}
/**
* Update Existing Item.
*
* @param int $product_id
* @param int $id
* @param array $data
*
* @return object
*/
protected function update($product_id, $id, $data)
{
return Query::init()
->setEndpoint("products/{$product_id}/variations")
->update($id, $data);
}
/**
* Destroy Item.
*
* @param int $product_id
* @param int $id
* @param array $options
*
* @return object
*/
protected function delete($product_id, $id, $options = [])
{
return Query::init()
->setEndpoint("products/{$product_id}/variations")
->delete($id, $options);
}
/**
* Batch Update.
*
* @param int $product_id
* @param array $data
*
* @return object
*/
protected function batch($product_id, $data)
{
return Query::init()
->setEndpoint("products/{$product_id}/variations")
->batch($data);
}
/**
* Paginate results.
*
* @param int $product_id
* @param int $per_page
* @param int $current_page
* @param array $options
*
* @return array
*/
protected function paginate(
$product_id,
$per_page = 10,
$current_page = 1,
$options = []
) {
return Query::init()
->setEndpoint("products/{$product_id}/variations")
->paginate($per_page, $current_page, $options);
}
/**
* Count all results.
*
* @param int $product_id
*
* @return int
*/
protected function count($product_id)
{
return Query::init()
->setEndpoint("products/{$product_id}/variations")
->count();
}
/**
* Store data.
*
* @param int $product_id
*
* @return array
*/
public function save($product_id)
{
return Query::init()
->setEndpoint("products/{$product_id}/variations")
->save();
}
}

View File

@@ -0,0 +1,12 @@
<?php
namespace Codexshaper\WooCommerce\Models;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Webhook extends BaseModel
{
use QueryBuilderTrait;
protected $endpoint = 'webhooks';
}

View File

@@ -0,0 +1,35 @@
<?php
namespace Codexshaper\WooCommerce;
use Codexshaper\WooCommerce\Models\BaseMOdel;
use Codexshaper\WooCommerce\Traits\QueryBuilderTrait;
class Query extends BaseMOdel
{
use QueryBuilderTrait;
protected $endpoint;
protected static $instance = null;
public function __construct($endpoint = '')
{
$this->endpoint = $endpoint;
}
public function setEndpoint($endpoint)
{
$this->endpoint = $endpoint;
return $this;
}
public function init()
{
if (!static::$instance) {
static::$instance = new static();
}
return static::$instance;
}
}

View File

@@ -0,0 +1,402 @@
<?php
namespace Codexshaper\WooCommerce\Traits;
use Codexshaper\WooCommerce\Facades\WooCommerce;
use Illuminate\Support\LazyCollection;
trait QueryBuilderTrait
{
/**
* @var
*/
protected $options = [];
/**
* @var
*/
protected $where = [];
/**
* @var
*/
protected $properties = [];
/**
* @var
*/
protected $isLazyCollection = false;
/**
* @var
*/
protected $isCollection = true;
/**
* @var
*/
protected $isOriginal = false;
/**
* Retrieve all Items.
*
* @param array $options
*
* @return array
*/
protected function all($options = [])
{
if ($this->isLazyCollection) {
return LazyCollection::make(WooCommerce::all($this->endpoint, $options));
}
if ($this->isCollection) {
return collect(WooCommerce::all($this->endpoint, $options));
}
return WooCommerce::all($this->endpoint, $options);
}
/**
* Retrieve single Item.
*
* @param int $id
* @param array $options
*
* @return object
*/
protected function find($id, $options = [])
{
if ($this->isLazyCollection) {
return LazyCollection::make(WooCommerce::find("{$this->endpoint}/{$id}", $options));
}
if ($this->isCollection) {
return collect(WooCommerce::find("{$this->endpoint}/{$id}", $options));
}
return WooCommerce::find("{$this->endpoint}/{$id}", $options);
}
/**
* Create new Item.
*
* @param array $data
*
* @return object
*/
protected function create($data)
{
if ($this->isLazyCollection) {
return LazyCollection::make(WooCommerce::create($this->endpoint, $data));
}
if ($this->isCollection) {
return collect(WooCommerce::create($this->endpoint, $data));
}
return WooCommerce::create($this->endpoint, $data);
}
/**
* Update Existing Item.
*
* @param int $id
* @param array $data
*
* @return object
*/
protected function update($id, $data)
{
if ($this->isLazyCollection) {
return LazyCollection::make(WooCommerce::update("{$this->endpoint}/{$id}", $data));
}
if ($this->isCollection) {
return collect(WooCommerce::update("{$this->endpoint}/{$id}", $data));
}
return WooCommerce::update("{$this->endpoint}/{$id}", $data);
}
/**
* Destroy Item.
*
* @param int $id
* @param array $options
*
* @return object
*/
protected function delete($id, $options = [])
{
if ($this->isLazyCollection) {
return LazyCollection::make(WooCommerce::delete("{$this->endpoint}/{$id}", $options));
}
if ($this->isCollection) {
return collect(WooCommerce::delete("{$this->endpoint}/{$id}", $options));
}
return WooCommerce::delete("{$this->endpoint}/{$id}", $options);
}
/**
* Batch Update.
*
* @param array $data
*
* @return object
*/
protected function batch($data)
{
if ($this->isLazyCollection) {
return LazyCollection::make(WooCommerce::create("{$this->endpoint}/batch", $data));
}
if ($this->isCollection) {
return collect(WooCommerce::create("{$this->endpoint}/batch", $data));
}
return WooCommerce::create("{$this->endpoint}/batch", $data);
}
/**
* Retrieve data.
*
* @return array
*/
protected function get()
{
if ($this->isLazyCollection) {
return LazyCollection::make(WooCommerce::all($this->endpoint, $this->options));
}
if ($this->isCollection) {
return collect(WooCommerce::all($this->endpoint, $this->options));
}
return WooCommerce::all($this->endpoint, $this->options);
}
/**
* Retrieve data.
*
* @return object
*/
protected function first()
{
if ($this->isLazyCollection) {
return LazyCollection::make($this->get()[0] ?? new \stdClass());
}
if ($this->isCollection) {
return collect($this->get()[0] ?? new \stdClass());
}
return collect($this->get()[0] ?? new \stdClass());
}
/**
* Set original.
*
* @return object $this
*/
protected function withOriginal()
{
$this->isOriginal = true;
$this->isCollection = false;
$this->isLazyCollection = false;
return $this;
}
/**
* Set collection.
*
* @return object $this
*/
protected function withCollection()
{
$this->isOriginal = false;
$this->isCollection = true;
$this->isLazyCollection = false;
return $this;
}
/**
* Set lazy collection.
*
* @return object $this
*/
protected function withLazyCollection()
{
$this->isOriginal = false;
$this->isCollection = false;
$this->isLazyCollection = true;
return $this;
}
/**
* Set options for woocommerce request.
*
* @param array $parameters
*
* @return object $this
*/
protected function options($parameters)
{
if (!is_array($parameters)) {
throw new \Exception('Options must be an array', 1);
}
if (empty($parameters)) {
throw new \Exception('Options must be pass at least one element', 1);
}
foreach ($parameters as $key => $value) {
$this->options[$key] = $value;
}
return $this;
}
/**
* Join options for woocommerce request.
*
* @param array $parameters
*
* @return object $this
*/
protected function where(...$parameters)
{
if (count($parameters) < 2 || count($parameters) > 3) {
throw new \Exception('You can pass minimum 2 and maximum 3 paramneters');
}
$field = strtolower($parameters[0]);
$value = count($parameters) == 3 ? $parameters[2] : $parameters[1];
switch ($field) {
case 'name': case 'title': case 'description':
$this->options['search'] = $value;
break;
default:
$this->options[$field] = $value;
break;
}
return $this;
}
/**
* Set order direction.
*
* @param string $name
* @param string $direction
*
* @return object $this
*/
protected function orderBy($name, $direction = 'desc')
{
$this->options['orderby'] = $name;
$this->options['order'] = $direction;
return $this;
}
/**
* Paginate results.
*
* @param int $per_page
* @param int $current_page
* @param array $options
*
* @return array
*/
protected function paginate($per_page = 10, $current_page = 1, $options = [])
{
try {
$this->options['per_page'] = (int) $per_page;
if ($current_page > 0) {
$this->options['page'] = (int) $current_page;
}
foreach ($options as $option => $value) {
$this->options[$option] = $value;
}
$data = $this->get();
$totalResults = WooCommerce::countResults();
$totalPages = WooCommerce::countPages();
$currentPage = WooCommerce::current();
$previousPage = WooCommerce::previous();
$nextPage = WooCommerce::next();
$pagination = [
'total_results' => $totalResults,
'total_pages' => $totalPages,
'current_page' => $currentPage,
'previous_page' => $previousPage,
'next_page' => $nextPage,
'first_page' => 1,
'last_page' => $totalResults,
];
$results = [
'meta' => $pagination,
'data' => $data,
];
if ($this->isLazyCollection) {
return LazyCollection::make($results);
}
if ($this->isCollection) {
return collect($results);
}
return $results;
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage(), 1);
}
}
/**
* Count all results.
*
* @return int
*/
protected function count()
{
try {
$results = WooCommerce::all($this->endpoint, $this->options);
$totalResults = WooCommerce::countResults();
return $totalResults;
} catch (\Exception $ex) {
throw new \Exception($ex->getMessage(), 1);
}
}
/**
* Store data.
*
* @return array
*/
public function save()
{
$this->results = WooCommerce::create($this->endpoint, $this->properties);
if ($this->isLazyCollection) {
return LazyCollection::make($this->results);
}
if ($this->isCollection) {
return collect($this->results);
}
return $this->results;
}
}

View File

@@ -0,0 +1,188 @@
<?php
namespace Codexshaper\WooCommerce\Traits;
trait WooCommerceTrait
{
/**
* GET method.
* Retrieve data.
*
* @param string $endpoint API endpoint.
* @param array $options
*
* @return array
*/
public function all($endpoint = '', $options = [])
{
try {
self::__construct();
return $this->client->get($endpoint, $options);
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 1);
}
}
/**
* GET method.
* Retrieve Single data.
*
* @param string $endpoint API endpoint.
* @param array $options
*
* @return array
*/
public function find($endpoint = '', $options = [])
{
try {
self::__construct();
return $this->client->get($endpoint, $options);
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 1);
}
}
/**
* POST method.
* Insert data.
*
* @param string $endpoint API endpoint.
* @param array $data
*
* @return array
*/
public function create($endpoint, $data)
{
try {
self::__construct();
return $this->client->post($endpoint, $data);
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 1);
}
}
/**
* PUT method.
* Update data.
*
* @param string $endpoint API endpoint.
* @param array $data
*
* @return array
*/
public function update($endpoint, $data)
{
try {
self::__construct();
return $this->client->put($endpoint, $data);
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 1);
}
}
/**
* DELETE method.
* Remove data.
*
* @param string $endpoint API endpoint.
* @param array $options
*
* @return array
*/
public function delete($endpoint, $options = [])
{
try {
self::__construct();
return $this->client->delete($endpoint, $options);
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 1);
}
}
/**
* Return the last request header.
*
* @return \Automattic\WooCommerce\HttpClient\Request
*/
public function getRequest()
{
try {
return $this->client->http->getRequest();
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 1);
}
}
/**
* Return the http response headers from last request.
*
* @return \Automattic\WooCommerce\HttpClient\Response
*/
public function getResponse()
{
try {
return $this->client->http->getResponse();
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 1);
}
}
/**
* Count the total results and return it.
*
* @return int
*/
public function countResults()
{
return (int) $this->getResponse()->getHeaders()[$this->headers['header_total']];
}
/**
* Count the total pages and return.
*
* @return mixed
*/
public function countPages()
{
return (int) $this->getResponse()->getHeaders()[$this->headers['header_total_pages']];
}
/**
* Return the current page number.
*
* @return int
*/
public function current()
{
return !empty($this->getRequest()->getParameters()['page']) ? $this->getRequest()->getParameters()['page'] : 1;
}
/**
* Return the previous page number.
*
* @return int|null
*/
public function previous()
{
$currentPage = $this->current();
return ($currentPage-- > 1) ? $currentPage : null;
}
/**
* Return the next page number.
*
* @return int|null
*/
public function next()
{
$currentPage = $this->current();
return ($currentPage++ < $this->countPages()) ? $currentPage : null;
}
}

View File

@@ -0,0 +1,51 @@
<?php
namespace Codexshaper\WooCommerce;
use Automattic\WooCommerce\Client;
use Codexshaper\WooCommerce\Traits\WooCommerceTrait;
class WooCommerceApi
{
use WooCommerceTrait;
/**
*@var \Automattic\WooCommerce\Client
*/
protected $client;
/**
*@var array
*/
protected $headers = [];
/**
* Build Woocommerce connection.
*
* @return void
*/
public function __construct()
{
try {
$this->headers = [
'header_total' => config('woocommerce.header_total') ?? 'X-WP-Total',
'header_total_pages' => config('woocommerce.header_total_pages') ?? 'X-WP-TotalPages',
];
$this->client = new Client(
config('woocommerce.store_url'),
config('woocommerce.consumer_key'),
config('woocommerce.consumer_secret'),
[
'version' => 'wc/'.config('woocommerce.api_version'),
'wp_api' => config('woocommerce.wp_api_integration'),
'verify_ssl' => config('woocommerce.verify_ssl'),
'query_string_auth' => config('woocommerce.query_string_auth'),
'timeout' => config('woocommerce.timeout'),
]
);
} catch (\Exception $e) {
throw new \Exception($e->getMessage(), 1);
}
}
}

View File

@@ -0,0 +1,38 @@
<?php
namespace Codexshaper\WooCommerce;
use Illuminate\Support\ServiceProvider;
class WooCommerceServiceProvider extends ServiceProvider
{
/**
* Boot the service provider.
*
* @return void
*/
public function boot()
{
$this->publishes([
__DIR__.'/config/woocommerce.php' => config_path('woocommerce.php'),
], 'woocommerce');
}
/**
* Register the service provider.
*
* @return void
*/
public function register()
{
$this->mergeConfigFrom(
__DIR__.'/config/woocommerce.php',
'woocommerce'
);
$this->app->singleton('WooCommerceApi', function () {
return new WooCommerceApi();
});
$this->app->alias('Codexshaper\Woocommerce\WooCommerceApi', 'WooCommerceApi');
}
}

View File

@@ -0,0 +1,73 @@
<?php
return [
/**
*================================================================================
* Store URL eg: http://example.com
*================================================================================.
*/
'store_url' => env('WOOCOMMERCE_STORE_URL', 'YOUR_STORE_URL'),
/**
*================================================================================
* Consumer Key
*================================================================================.
*/
'consumer_key' => env('WOOCOMMERCE_CONSUMER_KEY', 'YOUR_CONSUMER_KEY'),
/**
* Consumer Secret.
*/
'consumer_secret' => env('WOOCOMMERCE_CONSUMER_SECRET', 'YOUR_CONSUMER_SECRET'),
/**
*================================================================================
* SSL support
*================================================================================.
*/
'verify_ssl' => env('WOOCOMMERCE_VERIFY_SSL', false),
/**
*================================================================================
* Woocommerce API version
*================================================================================.
*/
'api_version' => env('WOOCOMMERCE_API_VERSION', 'v3'),
/**
*================================================================================
* Enable WP API Integration
*================================================================================.
*/
'wp_api' => env('WP_API_INTEGRATION', true),
/**
*================================================================================
* Force Basic Authentication as query string
*================================================================================.
*/
'query_string_auth' => env('WOOCOMMERCE_WP_QUERY_STRING_AUTH', false),
/**
*================================================================================
* Default WP timeout
*================================================================================.
*/
'timeout' => env('WOOCOMMERCE_WP_TIMEOUT', 15),
/**
*================================================================================
* Total results header
* Default value X-WP-Total
*================================================================================.
*/
'header_total' => env('WOOCOMMERCE_WP_HEADER_TOTAL', 'X-WP-Total'),
/**
*================================================================================
* Total pages header
* Default value X-WP-TotalPages
*================================================================================.
*/
'header_total_pages' => env('WOOCOMMERCE_WP_HEADER_TOTAL_PAGES', 'X-WP-TotalPages'),
];