new pisilinux web sites
This commit is contained in:
@@ -0,0 +1,40 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Controller\Factory;
|
||||
|
||||
class Cart extends Factory
|
||||
{
|
||||
const factory =
|
||||
[
|
||||
'methods' =>
|
||||
[
|
||||
'insertitem' => 'Insert::item',
|
||||
'insert' => 'Insert::item',
|
||||
'selectitems' => 'Select::items',
|
||||
'selectall' => 'Select::items',
|
||||
'selectobjects' => 'Select::objects',
|
||||
'selectitem' => 'Select::item',
|
||||
'select' => 'Select::item',
|
||||
'totalitems' => 'Total::items',
|
||||
'totalprices' => 'Total::prices',
|
||||
'updateitem' => 'Update::item',
|
||||
'update' => 'Update::item',
|
||||
'deleteitem' => 'Delete::item',
|
||||
'delete' => 'Delete::item',
|
||||
'deleteitems' => 'Delete::items',
|
||||
'deleteall' => 'Delete::items',
|
||||
'moneyformat' => 'Money::format',
|
||||
'formatmoney' => 'Money::format',
|
||||
'moneytonumber' => 'Money::number'
|
||||
]
|
||||
];
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Ability\Driver;
|
||||
|
||||
class CartExtends
|
||||
{
|
||||
use Driver;
|
||||
|
||||
/**
|
||||
* Driver
|
||||
*
|
||||
* @param array options
|
||||
* @param string construct
|
||||
*/
|
||||
const driver =
|
||||
[
|
||||
'options' => ['session', 'cookie'],
|
||||
'default' => 'ZN\Shopping\ShoppingDefaultConfiguration',
|
||||
'config' => 'Storage:shopping',
|
||||
'construct' => 'constructor'
|
||||
];
|
||||
|
||||
/**
|
||||
* Keeps key
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $key;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function constructor()
|
||||
{
|
||||
$this->key = md5('SystemCartData');
|
||||
|
||||
if( $sessionCart = $this->driver->select($this->key) )
|
||||
{
|
||||
Properties::$items = $sessionCart;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Delete extends CartExtends
|
||||
{
|
||||
/**
|
||||
* Delete item
|
||||
*
|
||||
* @param mixed $code
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function item($code) : bool
|
||||
{
|
||||
if( empty(Properties::$items) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( Properties::$items as $row )
|
||||
{
|
||||
if( is_array($code) )
|
||||
{
|
||||
if( isset($row[key($code)]) && $row[key($code)] == current($code) )
|
||||
{
|
||||
$code = $row[key($code)];
|
||||
}
|
||||
}
|
||||
|
||||
$key = array_search($code, $row);
|
||||
|
||||
if( ! empty($key) )
|
||||
{
|
||||
array_splice(Properties::$items, $i--, 1);
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $this->driver->insert($this->key, Properties::$items);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all items
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function items() : bool
|
||||
{
|
||||
Properties::$items = [];
|
||||
|
||||
return $this->driver->delete($this->key);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Insert extends CartExtends
|
||||
{
|
||||
/**
|
||||
* Insert item
|
||||
*
|
||||
* @param array $product
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function item(array $product) : bool
|
||||
{
|
||||
if( ! isset($product['quantity']) )
|
||||
{
|
||||
$product['quantity'] = 1;
|
||||
}
|
||||
|
||||
array_push(Properties::$items, $product);
|
||||
|
||||
$this->driver->insert($this->key, Properties::$items);
|
||||
|
||||
Properties::$items = $this->driver->select($this->key);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Helpers\Converter;
|
||||
|
||||
class Money
|
||||
{
|
||||
/**
|
||||
* Format money
|
||||
*
|
||||
* @param int $money
|
||||
* @param string $type = NULL
|
||||
*
|
||||
* @return string
|
||||
*/
|
||||
public function format(int $money, ?string $type = NULL) : string
|
||||
{
|
||||
return Converter::money($money, $type);
|
||||
}
|
||||
|
||||
/**
|
||||
* Money to number
|
||||
*
|
||||
* @param string $money
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function number($money) : Float
|
||||
{
|
||||
return Converter::moneyToNumber($money);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Properties
|
||||
{
|
||||
/**
|
||||
* Keeps items
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
public static $items = [];
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
use ZN\Helpers\Converter;
|
||||
|
||||
class Select extends CartExtends
|
||||
{
|
||||
/**
|
||||
* Select all items object type
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function objects() : object
|
||||
{
|
||||
return Converter::toObjectRecursive($this->items());
|
||||
}
|
||||
|
||||
/**
|
||||
* Select all items
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function items() : array
|
||||
{
|
||||
return Properties::$items ?: [];
|
||||
}
|
||||
|
||||
/**
|
||||
* Select item
|
||||
*
|
||||
* @param mixed $code
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function item($code)
|
||||
{
|
||||
if( empty(Properties::$items) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
foreach( Properties::$items as $row )
|
||||
{
|
||||
if( ! is_array($code) )
|
||||
{
|
||||
$key = array_search($code, $row);
|
||||
}
|
||||
else
|
||||
{
|
||||
if( isset($row[key($code)]) && $row[key($code)] == current($code) )
|
||||
{
|
||||
$key = $row;
|
||||
}
|
||||
}
|
||||
|
||||
if( ! empty($key) )
|
||||
{
|
||||
return (object) $row;
|
||||
}
|
||||
}
|
||||
|
||||
return false; // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
/**
|
||||
* Default Configuration
|
||||
*
|
||||
* Enabled when the configuration file can not be accessed.
|
||||
*/
|
||||
class ShoppingDefaultConfiguration
|
||||
{
|
||||
/*
|
||||
|--------------------------------------------------------------------------
|
||||
| Shopping
|
||||
|--------------------------------------------------------------------------
|
||||
|
|
||||
| It is specified in which structure the cart data information will be stored.
|
||||
|
|
||||
*/
|
||||
|
||||
public $driver = 'session';
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Total extends CartExtends
|
||||
{
|
||||
/**
|
||||
* Total items
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return int
|
||||
*/
|
||||
public function items() : int
|
||||
{
|
||||
$totalItems = 0;
|
||||
|
||||
if( ! empty(Properties::$items) ) foreach( Properties::$items as $item )
|
||||
{
|
||||
$totalItems += $item['quantity'];
|
||||
}
|
||||
|
||||
return $totalItems;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Total prices
|
||||
*
|
||||
* @param void
|
||||
*
|
||||
* @return float
|
||||
*/
|
||||
public function prices() : Float
|
||||
{
|
||||
$total = 0;
|
||||
|
||||
if( ! empty(Properties::$items) ) foreach( Properties::$items as $values )
|
||||
{
|
||||
$quantity = (int) ($values['quantity'] ?? 1);
|
||||
$price = (float) ($values['price'] ?? 0);
|
||||
|
||||
$total += $price * $quantity;
|
||||
}
|
||||
|
||||
return $total;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,67 @@
|
||||
<?php namespace ZN\Shopping;
|
||||
/**
|
||||
* ZN PHP Web Framework
|
||||
*
|
||||
* "Simplicity is the ultimate sophistication." ~ Da Vinci
|
||||
*
|
||||
* @package ZN
|
||||
* @license MIT [http://opensource.org/licenses/MIT]
|
||||
* @author Ozan UYKUN [ozan@znframework.com]
|
||||
*/
|
||||
|
||||
class Update extends CartExtends
|
||||
{
|
||||
/**
|
||||
* Update item
|
||||
*
|
||||
* @param mixed $code
|
||||
* @param array $data
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function item($code, array $data) : bool
|
||||
{
|
||||
if( empty(Properties::$items) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
$i = 0;
|
||||
|
||||
foreach( Properties::$items as $row )
|
||||
{
|
||||
if( is_array($code) )
|
||||
{
|
||||
if(isset($row[key($code)]) && $row[key($code)] == current($code))
|
||||
{
|
||||
$code = $row[key($code)];
|
||||
}
|
||||
}
|
||||
|
||||
$key = array_search($code,$row);
|
||||
|
||||
if( ! empty($key) )
|
||||
{
|
||||
array_splice(Properties::$items, $i, 1);
|
||||
|
||||
if( count($data) !== count($row) )
|
||||
{
|
||||
foreach( $data as $k => $v )
|
||||
{
|
||||
$row[$k] = $v;
|
||||
}
|
||||
|
||||
array_push(Properties::$items, $row);
|
||||
}
|
||||
else
|
||||
{
|
||||
array_push(Properties::$items, $data); // @codeCoverageIgnore
|
||||
}
|
||||
}
|
||||
|
||||
$i++;
|
||||
}
|
||||
|
||||
return $this->driver->insert($this->key, Properties::$items);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user