Commit e3f24db6 authored by Mario's avatar Mario

cart: improved min version check, add new catalogitem widget, add item photo...

cart: improved min version check, add new catalogitem widget, add item photo url to sku, some code format fixes
parent 9af1ae20
......@@ -26,36 +26,27 @@ use Zotlabs\Extend\Route;
class Cart {
public static $cart_version="0.9.0";
public static $seller;
public static $buyer;
public static function check_min_version ($platform,$minver) {
switch ($platform) {
case 'hubzilla':
$curver = STD_VERSION;
break;
case 'cart':
$curver = Cart::$cart_version;
break;
default:
return false;
}
$checkver = explode ('.',$minver);
$ver = explode ('.',$curver);
$major = (intval($checkver[0]) <= intval($ver[0]));
$minor = (intval($checkver[1]) <= intval($ver[1]));
$patch = (intval($checkver[2]) <= intval($ver[2]));
public static $cart_version="0.9.0";
public static $seller;
public static $buyer;
public static function check_min_version($platform,$minver) {
switch ($platform) {
case 'hubzilla':
$curver = STD_VERSION;
break;
case 'cart':
$curver = Cart::$cart_version;
break;
default:
return false;
}
if ($major && $minor && $patch) {
return true;
} else {
return false;
}
}
if(version_compare($curver, $minver) >= 0)
return true;
return false;
}
public static function get_seller_id() {
return (isset(\App::$profile["profile_uid"]) && \App::$profile["profile_uid"] != null) ? \App::$profile["profile_uid"] : Cart::$seller["channel_id"];
......@@ -811,6 +802,7 @@ function cart_calc_totals(&$hookdata) {
$subtotal=0;
$taxtotal=0;
$ordertotal=0;
foreach ($items as $key=>$item) {
$linetotal=floatval($item["item_qty"])*floatval($item["item_price"]);
$hookdata["order"]["items"][$key]["extended"]=$linetotal;
......@@ -1161,6 +1153,7 @@ function cart_load(){
// WIDGET REGISTRATION
if (Cart::check_min_version ('hubzilla','3.7.1')) {
Zotlabs\Extend\Widget::register('addon/cart/widgets/cartbutton.php','cartbutton');
Zotlabs\Extend\Widget::register('addon/cart/widgets/catalogitem.php','catalogitem');
}
//$manualpayments = get_pconfig ($id,'cart','enable_manual_payments');
......@@ -1187,6 +1180,7 @@ function cart_unload(){
// WIDGET UNREGISTRATION
if (Cart::check_min_version ('hubzilla','3.7.1')) {
Zotlabs\Extend\Widget::unregister('addon/cart/widgets/cartbutton.php','cartbutton');
Zotlabs\Extend\Widget::unregister('addon/cart/widgets/catalogitem.php','catalogitem');
}
Route::unregister('addon/cart/Settings/Cart.php','settings/cart');
......
......@@ -98,6 +98,7 @@ class Cart_hzservices {
$catalog[$item["item_sku"]] = Array("item_sku"=>$item["item_sku"],
"item_desc"=>$item["item_description"],
"item_price"=>$item["item_price"],
"item_photo_url"=>$item["item_photo_url"],
"item_type"=>"hzservices",
"item_activate_commands"=>$item["activate_commands"],
"item_deactivate_commands"=>$item["deactivate_commands"],
......@@ -197,6 +198,7 @@ class Cart_hzservices {
}
$item["item_description"] = isset($_POST["item_description"]) ? $_POST["item_description"] : $item["item_description"];
$item["item_price"] = isset($_POST["item_price"]) ? $_POST["item_price"]+0 : $item["item_price"];
$item["item_photo_url"] = isset($_POST["item_photo_url"]) ? $_POST["item_photo_url"] : $item["item_photo_url"];
$item["item_active"] = isset($_POST["item_active"]) ? true : false;
$item["item_locked"] = isset($_POST["item_locked"]) ? true : false;
$skus[$sku]=$item;
......@@ -635,7 +637,7 @@ class Cart_hzservices {
$skus = get_pconfig(local_channel(),'cart-hzservices','skus');
$items = $skus ? cart_maybeunjson($skus) : Array();
$item= isset ($items[$sku]) ? $items[$sku] : Array("item_sku"=>$sku,"locked"=>0,"item_description"=>"New Item","item_price"=>0,"item_active"=>false);
$item= isset ($items[$sku]) ? $items[$sku] : Array("item_sku"=>$sku,"locked"=>0,"item_description"=>"New Item","item_price"=>0,"item_photo_url"=>"","item_active"=>false);
$formelements["submit"]=t("Submit");
$formelements["uri"]=strtok($_SERVER["REQUEST_URI"],'?').'?SKU='.$sku;
......@@ -654,6 +656,9 @@ class Cart_hzservices {
$formelements["itemdetails"].= replace_macros(get_markup_template('field_input.tpl'), array(
'$field' => array('item_price', t('Price'),
(isset($item["item_price"]) ? $item["item_price"] : "0.00"))));
$formelements["itemdetails"].= replace_macros(get_markup_template('field_input.tpl'), array(
'$field' => array('item_photo_url', t('Photo URL'),
(isset($item["item_photo_url"]) ? $item["item_photo_url"] : ''))));
$formelements["itemactivation"].= "<h3><u>Channel Commands</u></h3>\n";
$formelements["itemactivation"].= replace_macros(get_markup_template('field_radio.tpl'), array(
'$field' => array('cmd', t('Add buyer to privacy group'),
......
......@@ -98,6 +98,7 @@ class Cart_manualcat {
Array("item_sku"=>$item,
"item_desc"=>$skudata["item_description"],
"item_price"=>$skudata["item_price"],
"item_photo_url"=>$skudata["item_photo_url"],
"item_meta"=>cart_maybeunjson($skudata["item_meta"]),
"item_type"=>"manualcat",
"locked"=>$skudata["locked"]
......@@ -211,6 +212,7 @@ class Cart_manualcat {
}
$item["item_description"] = isset($_POST["item_description"]) ? $_POST["item_description"] : $item["item_description"];
$item["item_price"] = isset($_POST["item_price"]) ? $_POST["item_price"]+0 : $item["item_price"];
$item["item_photo_url"] = isset($_POST["item_photo_url"]) ? $_POST["item_photo_url"] : $item["item_photo_url"];
$item["item_active"] = isset($_POST["item_active"]) ? true : false;
$item["item_locked"] = isset($_POST["item_locked"]) ? true : false;
if ($item["item_active"]) {
......@@ -243,7 +245,7 @@ class Cart_manualcat {
$seller_uid = Cart::get_seller_id();
$skudata= Cart_manualcat::get_item($sku);
$item= (is_array($skudata) && $skudata["item_sku"]=$sku) ? $skudata : Array("item_sku"=>$sku,"locked"=>0,"item_description"=>"New Item","item_price"=>0,"item_active"=>false);
$item= (is_array($skudata) && $skudata["item_sku"]=$sku) ? $skudata : Array("item_sku"=>$sku,"locked"=>0,"item_description"=>"New Item","item_price"=>0,"item_photo_url"=>"","item_active"=>false);
$formelements["submit"]=t("Submit");
$formelements["uri"]=strtok($_SERVER["REQUEST_URI"],'?').'?SKU='.$sku;
......@@ -262,6 +264,9 @@ class Cart_manualcat {
$formelements["itemdetails"].= replace_macros(get_markup_template('field_input.tpl'), array(
'$field' => array('item_price', t('Price'),
(isset($item["item_price"]) ? $item["item_price"] : "0.00"))));
$formelements["itemdetails"].= replace_macros(get_markup_template('field_input.tpl'), array(
'$field' => array('item_photo_url', t('Photo URL'),
(isset($item["item_photo_url"]) ? $item["item_photo_url"] : ''))));
$macrosubstitutes=Array("security_token"=>get_form_security_token(),"sku"=>$sku,"formelements"=>$formelements);
......
......@@ -8,6 +8,7 @@
<div class="section-content-wrapper">
<table class="w-100">
<tr>
<th></th>
<th></th>
<th>Description</th>
<th>Price each {{if $currencysymbol}}({{$currencysymbol}}){{/if}}</th>
......@@ -23,6 +24,7 @@
</form>
</td>
<td>{{if $item.item_photo_url}}<img src="{{$item.item_photo_url}}" style="max-height: 2.5rem; max-width: 2.5rem">{{/if}}</td>
<td>{{$item.item_desc}}</td>
<td>{{$item.item_price}}</td>
<td>{{if $item.order_qty}}<i class="fa fa-shopping-cart"></i> {{$item.order_qty}}{{/if}}</td>
......
......@@ -8,7 +8,7 @@
<input class="form-control form-control-sm" type="text" name="qty-{{$item.id}}" value="{{$item.order_qty}}" style="width: 4em;float:left;">
<div class="input-group-append">
<button class="btn btn-sm btn-primary" type="submit" name="Submit" value="{{$item.item_sku}}">Update Quantity</button>
<button class="btn btn-sm btn-outline-danger btn-outline border-0" type="submit" name="delsku" value="{{$item.item_sku}}" title="Remove from cart"><i class="fa fa-remove"></i></button>
<button class="btn btn-sm btn-outline-danger btn-outline" type="submit" name="delsku" value="{{$item.item_sku}}" title="Remove from cart"><i class="fa fa-remove"></i></button>
</div>
</div>
</form>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment