ver. 0.290: ShopCoupon + ShopOrder frontend migration to Domain + Controllers
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,77 +1,83 @@
|
||||
<?
|
||||
<?php
|
||||
namespace shop;
|
||||
class Coupon implements \ArrayAccess
|
||||
{
|
||||
private $data = [];
|
||||
|
||||
public function __construct( int $element_id )
|
||||
{
|
||||
global $mdb;
|
||||
if ( $element_id )
|
||||
{
|
||||
$result = $mdb -> get( 'pp_shop_coupon', '*', [ 'id' => $element_id ] );
|
||||
if ( \Shared\Helpers\Helpers::is_array_fix( $result ) ) foreach ( $result as $key => $val )
|
||||
$this -> $key = $val;
|
||||
if ( is_array( $result ) )
|
||||
$this -> data = $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public function load_from_db_by_name( string $name )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$result = $mdb -> get( 'pp_shop_coupon', '*', [ 'name' => $name ] );
|
||||
if ( is_array( $result ) ) foreach ( $result as $key => $val )
|
||||
$this -> $key = $val;
|
||||
if ( is_array( $result ) )
|
||||
$this -> data = $result;
|
||||
}
|
||||
|
||||
public function is_one_time() {
|
||||
// return $this -> bean -> one_time;
|
||||
public function is_one_time()
|
||||
{
|
||||
return (bool)( $this -> data['one_time'] ?? 0 );
|
||||
}
|
||||
|
||||
public function is_available()
|
||||
{
|
||||
if ( !$this -> id )
|
||||
if ( !( $this -> data['id'] ?? 0 ) )
|
||||
return false;
|
||||
|
||||
if ( !$this -> status )
|
||||
if ( !( $this -> data['status'] ?? 0 ) )
|
||||
return false;
|
||||
|
||||
return !$this -> used;
|
||||
return !( $this -> data['used'] ?? 0 );
|
||||
}
|
||||
|
||||
public function set_as_used()
|
||||
{
|
||||
// $this -> bean -> used = 1;
|
||||
// $this -> bean -> date_used = date( 'Y-m-d H:i:s' );
|
||||
// \R::store( $this -> bean );
|
||||
$id = (int)( $this -> data['id'] ?? 0 );
|
||||
if ( $id > 0 )
|
||||
{
|
||||
global $mdb;
|
||||
$repo = new \Domain\Coupon\CouponRepository( $mdb );
|
||||
$repo -> markAsUsed( $id );
|
||||
$this -> data['used'] = 1;
|
||||
}
|
||||
}
|
||||
|
||||
public function __get( $variable )
|
||||
{
|
||||
if ( array_key_exists( $variable, $this -> data ) )
|
||||
return $this -> $variable;
|
||||
return isset( $this -> data[$variable] ) ? $this -> data[$variable] : null;
|
||||
}
|
||||
|
||||
public function __set( $variable, $value )
|
||||
{
|
||||
$this -> $variable = $value;
|
||||
$this -> data[$variable] = $value;
|
||||
}
|
||||
|
||||
public function offsetExists( $offset )
|
||||
{
|
||||
return isset( $this -> $offset );
|
||||
return isset( $this -> data[$offset] );
|
||||
}
|
||||
|
||||
public function offsetGet( $offset )
|
||||
{
|
||||
return $this -> $offset;
|
||||
return isset( $this -> data[$offset] ) ? $this -> data[$offset] : null;
|
||||
}
|
||||
|
||||
public function offsetSet( $offset, $value )
|
||||
{
|
||||
$this -> $offset = $value;
|
||||
$this -> data[$offset] = $value;
|
||||
}
|
||||
|
||||
public function offsetUnset( $offset )
|
||||
{
|
||||
unset( $this -> $offset );
|
||||
unset( $this -> data[$offset] );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -166,7 +166,8 @@ class Order implements \ArrayAccess
|
||||
{
|
||||
global $settings;
|
||||
|
||||
$order = \front\factory\ShopOrder::order_details( $this -> id );
|
||||
global $mdb;
|
||||
$order = ( new \Domain\Order\OrderRepository( $mdb ) )->orderDetailsFrontend( $this -> id );
|
||||
$coupon = (int)$order['coupon_id'] ? new \shop\Coupon( (int)$order['coupon_id'] ) : null;
|
||||
|
||||
$mail_order = \Shared\Tpl\Tpl::view( 'shop-order/mail-summary', [
|
||||
|
||||
Reference in New Issue
Block a user