Skip to content

Commit

Permalink
fixes on guest user
Browse files Browse the repository at this point in the history
  • Loading branch information
Filippo Matteo Riggio committed Oct 9, 2020
1 parent 97050e9 commit 5104248
Show file tree
Hide file tree
Showing 22 changed files with 166 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ public function up()
$table->string('label', 255);
$table->text('description')->nullable();
$table->string('lang', 5);
$table->boolean('show_in_home');

$table->bigInteger('image')->unsigned()->nullable(true);

Expand Down
3 changes: 3 additions & 0 deletions src/FactotumServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@
use Kaleidoscope\Factotum\Observers\CategoryObserver;
use Kaleidoscope\Factotum\Observers\DiscountCodeObserver;
use Kaleidoscope\Factotum\Observers\OrderObserver;
use Kaleidoscope\Factotum\Observers\ProductObserver;



use Kaleidoscope\Factotum\Console\Commands\FactotumCleanFolders;
Expand Down Expand Up @@ -191,6 +193,7 @@ public function boot(GateContract $gate)

if ( env('FACTOTUM_ECOMMERCE_INSTALLED') ) {
Order::observe(OrderObserver::class);
Product::observe(ProductObserver::class);
DiscountCode::observe(DiscountCodeObserver::class);
}

Expand Down
8 changes: 8 additions & 0 deletions src/app/Brand.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class Brand extends Model
'deleted_at'
];

protected $appends = [
'total_products'
];

public function products() {
return $this->hasMany('Kaleidoscope\Factotum\Product');
Expand All @@ -45,4 +48,9 @@ public function getLogoAttribute($value)
return null;
}

public function getTotalProductsAttribute()
{
return Product::where('brand_id', $this->id)->count();
}

}
2 changes: 1 addition & 1 deletion src/app/Helpers/PrintProductCategoriesHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private static function print_product_categories_items( $productCategories, $bas
$html .= '<li class="category-item category-item-' . $level . '">' . "\n";
$html .= '<div class="flexed">' . "\n";
$html .= '<a href="' . $baseURL . '/' . $item->name . '"'
.' class="' . ( $productCategory && $item->id == $productCategory->id ? 'active' : '' ) . '">' . $item->label . '</a>' . "\n";
.' class="' . ( $productCategory && $item->id == $productCategory->id ? 'active' : '' ) . '">' . ucfirst(strtolower($item->label)) . ' (' . $item->total_products . ')</a>' . "\n";

if ( $showChilds && $item->childs->count() > 0 ) {
$html .= '<button class="toggle-subcategory"><i class="fi flaticon-down-arrow"></i></button>';
Expand Down
11 changes: 0 additions & 11 deletions src/app/Http/Controllers/Api/Campaign/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,4 @@ public function update(StoreCampaign $request, $id)
return response()->json( [ 'result' => 'ok', 'campaign' => $campaign ] );
}

public function updateFilter(StoreCampaignFilter $request, $id)
{
$filter = $request->input('filter');

$campaign = Campaign::find( $id );
$campaign->filter = $filter;
$campaign->save();

return response()->json( [ 'result' => 'ok', 'campaign' => $campaign ] );
}

}
6 changes: 4 additions & 2 deletions src/app/Http/Controllers/Api/Order/UpdateController.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,10 @@ public function changeOrdersStatus(Request $request)
if ( $orders && count($orders) > 0 ) {
foreach ( $orders as $orderId ) {
$order = Order::find($orderId);
$order->status = $status;
$order->save();
if ( $order ) {
$order->status = $status;
$order->save();
}
}
}

Expand Down
10 changes: 8 additions & 2 deletions src/app/Http/Controllers/Api/Product/ReadController.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,14 @@ public function getListPaginated( Request $request )
$query->where('active', true );
}

if ( isset($filters['featured']) && $filters['featured'] ) {
$query->where('featured', true );
}

}

$totalCountQuery = clone $query;

$query->orderBy($sort, $direction);

if ( $limit ) {
Expand All @@ -76,7 +82,7 @@ public function getListPaginated( Request $request )

$products = $query->get();

return response()->json( [ 'result' => 'ok', 'products' => $products, 'total' => Product::count() ]);
return response()->json( [ 'result' => 'ok', 'products' => $products, 'total' => $totalCountQuery->count() ]);
}


Expand All @@ -92,7 +98,7 @@ public function getListBySearch( Request $request )
{
$search = $request->input('search');

$query = Product::where( 'title', 'like', '%' . $search . '%' )
$query = Product::where( 'name', 'like', '%' . $search . '%' )
->orWhere( 'code', 'like', '%' . $search . '%' );

$productList = $query->get();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public function ajaxGetCartPanel( Request $request )

$result = [
'result' => 'ok',
'cart_id' => $cart->id,
'totalProducts' => $totals['totalProducts'],
'totalPartial' => '€' . number_format( $totals['totalPartial'], 2, ',', '.' ),
'totalTaxes' => '€' . number_format( $totals['totalTaxes'], 2, ',', '.' ),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ public function prepareCheckout( Request $request )
->where( 'customer_id', $user->id )
->orderBy('default_address', 'DESC')
->get();
} else {
$request->session()->remove('delivery_address');
$request->session()->remove('invoice_address');
$request->session()->remove('shipping');
}


Expand Down Expand Up @@ -296,6 +300,9 @@ public function setGuestDeliveryAddress( StoreGuestCustomerDeliveryAddress $requ

if ( $deliveryAddress ) {
$request->session()->put('delivery_address', $deliveryAddress->id );
$request->session()->remove('invoice_address');
$request->session()->remove('shipping');

return $request->wantsJson() ? json_encode([ 'result' => 'ok' ]) : redirect()->back();
}
}
Expand Down
1 change: 1 addition & 0 deletions src/app/Http/Requests/StoreProductCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public function rules()

$productCategoriesViaPim = config('factotum.product_categories_via_pim');

// TODO: categoria unique ma solo su categorie non "deleted_at"
if ( !$productCategoriesViaPim ) {

$rules = [
Expand Down
19 changes: 19 additions & 0 deletions src/app/Observers/ProductObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<?php

namespace Kaleidoscope\Factotum\Observers;

use Illuminate\Support\Facades\DB;

use Kaleidoscope\Factotum\Product;
use Kaleidoscope\Factotum\CartProduct;


class ProductObserver
{

public function deleting(Product $product)
{
CartProduct::where('product_id', $product->id)->delete();
}

}
2 changes: 1 addition & 1 deletion src/app/Order.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ public function sendOrderStatusChangeNotification()
$customer = User::with('profile')->find( $this->customer_id );
}

if ( file_exists(app_path('Notifications/NewOrderToCustomerNotification.php')) ) {
if ( file_exists(app_path('Notifications/OrderStatusChangeToCustomerNotification.php')) ) {
Notification::send( $customer, new \App\Notifications\OrderStatusChangeToCustomerNotification( $customer, $this ) );
} else {
Notification::send( $customer, new OrderStatusChangeToCustomerNotification( $customer, $this ) );
Expand Down
23 changes: 21 additions & 2 deletions src/app/ProductCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Response;

class ProductCategory extends Model
Expand All @@ -18,15 +19,17 @@ class ProductCategory extends Model
'lang',
'image',
'description',
'order_no'
'order_no',
'show_in_home'
];

protected $hidden = [
'created_at', 'updated_at', 'deleted_at'
];

protected $appends = [
'abs_url'
'abs_url',
'total_products'
];

public function products()
Expand Down Expand Up @@ -262,4 +265,20 @@ public function getAbsUrlAttribute( $value )
return $value;
}

public function getTotalProductsAttribute()
{
$tmp = [ $this->id ];
$childs = $this->singleCategoryFlatTreeChildsArray( null, null );

if ( $childs && count($childs) > 0 ) {
foreach ( $childs as $c ) {
$tmp[] = $c->id;
}
}

return DB::table('products')
->whereIn('product_category_id', $tmp)
->count();
}

}
13 changes: 12 additions & 1 deletion src/app/Traits/CartUtils.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,6 @@ protected function _getShippingOptions( $countryCode = null)

if ( $deliveryAddress ) {
$countryCode = strtoupper($deliveryAddress->country);

}

if ( $countryCode ) {
Expand All @@ -256,6 +255,18 @@ protected function _getShippingOptions( $countryCode = null)
'label' => Lang::get('factotum::ecommerce_checkout.shipping_' . $countryCode . '_' . $shippingType )
];
}

} else {

$shippingTypes = $shippingOptions[ 'other' ];

foreach ( $shippingTypes as $shippingType => $amount ) {
$tmp[ 'other_' . $shippingType ] = [
'amount' => $amount,
'label' => Lang::get('factotum::ecommerce_checkout.shipping_other_' . $shippingType )
];
}

}

} else {
Expand Down
2 changes: 1 addition & 1 deletion src/config/factotum.php
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,6 @@
'min_free_shipping' => 65,


'version' => '5.0.10',
'version' => '5.0.11',

];
6 changes: 4 additions & 2 deletions src/resources/lang/en-GB/ecommerce_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@
'shipping_italy' => 'Express Delivery in Italy',
'shipping_abroad' => 'Express Delivery abroad',

'shipping_IT_express' => 'Italy express',
'shipping_IT_standard' => 'Italy standard',
'shipping_IT_express' => 'Italy - Express',
'shipping_IT_standard' => 'Italy - Standard',

'shipping_other_standard' => 'Abroad - Standard',

'delivery_address_title' => 'delivery address',
'invoice_address_title' => 'invoice address',
Expand Down
5 changes: 4 additions & 1 deletion src/resources/lang/it-IT/ecommerce_cart.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
'product_dropped' => 'Prodotto rimosso dal carrello!',
'product_drop_error' => 'Impossibile rimuovere un prodotto dal carrello!',

'max_quantity_reached' => 'Quantità massima raggiunta!'
'max_quantity_reached' => 'Quantità massima raggiunta!',

'free_shipping' => 'Gratuita',
'shipping_not_calculated' => '<small>Calcolata alla cassa</small>'
];
40 changes: 40 additions & 0 deletions src/resources/lang/it-IT/ecommerce_checkout.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,44 @@
'shipping_pick_up' => 'Ritiro presso la nostra sede',
'shipping_italy' => 'Consegna in tutta Italia tramite Corriere Espresso',
'shipping_abroad' => 'Consegna per l\'estero tramite Corriere Espresso',


'shipping_IT_express' => 'Espressa - Italia',
'shipping_IT_standard' => 'Standard - Italia',

'shipping_other_standard' => 'Standard - Estero',

'delivery_address_title' => 'Indirizzo di consegna',
'invoice_address_title' => 'Indirizzo di fatturazione',
'shipping_title' => 'Spedizione',
'payment_title' => 'Metodo di Pagamento',

'first_name' => 'Nome',
'last_name' => 'Cognome',
'email' => 'Email',
'phone' => 'Telefono',
'company_name' => 'Nome Azienda',
'additional_notes' => 'Note aggiuntive',

'delivery_address' => 'Indirizzo di consegna',
'delivery_address_line_2' => 'Indirizzo di consegna - dati aggiuntivi',
'delivery_city' => 'Città',
'delivery_zip' => 'CAP',
'delivery_province' => 'Provincia',
'delivery_country' => 'Nazione',

'invoice_address' => 'Indirizzo di fatturazione',
'invoice_address_line_2' => 'Indirizzo di fatturazione - dati aggiuntivi',
'invoice_city' => 'Città',
'invoice_zip' => 'CAP',
'invoice_province' => 'Provincia',
'invoice_country' => 'Nazione',

'use_same_address_as_invoice_address' => 'Usa lo stesso indirizzo per la fatturazione',
'select_delivery_address_first' => 'Seleziona prima l\'indirizzo di consegna',

'agree_terms_conditions' => 'Aderisco ai termini e condizioni',
'credit_or_debit_cart' => 'Carta di debito o credito',
'pay_with_credit_or_debit_cart' => 'Paga con Carta di debito o credito',
'custom_payment_in_agreement_with' => 'Pagamento secondo accordi'
];
9 changes: 9 additions & 0 deletions src/resources/lang/it-IT/ecommerce_order.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,13 @@
'refunded' => 'Rimborsato',
'failed' => 'Fallito',


'product' => 'Prodotto',
'quantity' => 'Quantità',
'price' => 'Prezzo',
'total_partial' => 'Subtotale',
'total_taxes' => 'Totale Tasse',
'total_shipping' => 'Totale Spedizione',
'payment_method' => 'Metodo di pagamento',
'total' => 'Totale'
];
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
<td class="tar">
<span class="total-shipping">
@if( $totalShipping )
{{ '' . number_format( $totalShipping, 2, ',', '.' ) }}
{!! $totalShipping !!}
@else
-
@endif
Expand Down

0 comments on commit 5104248

Please sign in to comment.