minor fixes
This commit is contained in:
@@ -29,7 +29,7 @@ class ArticleNatures
|
||||
public static function getIdBySlug($slug)
|
||||
{
|
||||
$model = self::getBySlug($slug);
|
||||
|
||||
|
||||
return $model ? $model->id : false;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,11 +4,11 @@ namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Article;
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Repositories\Botanic\Species;
|
||||
use App\Repositories\Botanic\Varieties;
|
||||
use App\Repositories\Core\Comments;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Traits\Repository\Imageable;
|
||||
use Illuminate\Support\Str;
|
||||
|
||||
@@ -245,7 +245,7 @@ class Articles
|
||||
public static function getArticleNaturesOptionsWithOffers($options = false)
|
||||
{
|
||||
$ids = self::getArticleNaturesIdsWithOffers($options);
|
||||
|
||||
|
||||
}
|
||||
|
||||
public static function getArticleNaturesWithOffers($options = false)
|
||||
@@ -342,7 +342,7 @@ class Articles
|
||||
switch ($product_type) {
|
||||
case 'App\Models\Botanic\Variety':
|
||||
$product = Varieties::get($product_id);
|
||||
if (!$product) {
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
@@ -358,7 +358,7 @@ class Articles
|
||||
break;
|
||||
case 'App\Models\Botanic\Specie':
|
||||
$product = Species::get($product_id);
|
||||
if (!$product) {
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
@@ -369,7 +369,7 @@ class Articles
|
||||
break;
|
||||
case 'App\Models\Shop\Merchandise':
|
||||
$product = Merchandises::get($product_id);
|
||||
if (!$product) {
|
||||
if (! $product) {
|
||||
break;
|
||||
}
|
||||
$data[] = [
|
||||
|
||||
@@ -19,7 +19,7 @@ class Baskets
|
||||
public static function getBasketTotal($deliveryId = false, $deliveryTypeId = false)
|
||||
{
|
||||
$saleChannelId = Deliveries::getSaleChannelId($deliveryId);
|
||||
|
||||
|
||||
return self::getBasketSummary($saleChannelId, $deliveryTypeId);
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ class Baskets
|
||||
$totalWeight += $weight;
|
||||
}
|
||||
$shipping = DeliveryTypeCalculations::getPriceByDeliveryType($deliveryTypeId, $totalWeight);
|
||||
|
||||
|
||||
$data = [
|
||||
'detail' => $detail,
|
||||
'total' => $total,
|
||||
@@ -84,7 +84,7 @@ class Baskets
|
||||
$weight = $offer->weight * $item->quantity;
|
||||
$totalWeight += $weight;
|
||||
}
|
||||
|
||||
|
||||
return $totalWeight;
|
||||
}
|
||||
|
||||
|
||||
21
app/Repositories/Shop/CustomerSaleChannels.php
Normal file
21
app/Repositories/Shop/CustomerSaleChannels.php
Normal file
@@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\CustomerSaleChannel;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class CustomerSaleChannels
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function destroyByCustomerAndSaleChannel($customerId, $saleChannelId)
|
||||
{
|
||||
return CustomerSaleChannel::byCustomer($customerId)->bySaleChannel($saleChannelId)->delete();
|
||||
}
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return CustomerSaleChannel::query();
|
||||
}
|
||||
}
|
||||
@@ -14,6 +14,27 @@ class Customers
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return [
|
||||
'sale_channels' => SaleChannels::getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getSaleChannelIds($customerId = false)
|
||||
{
|
||||
$channels = self::getSaleChannels($customerId);
|
||||
|
||||
return $channels ? $channels->pluck('id')->toArray() : false;
|
||||
}
|
||||
|
||||
public static function getSaleChannels($customerId = false)
|
||||
{
|
||||
$customer = $customerId ? self::get($customerId) : self::getAuth();
|
||||
|
||||
return $customer ? $customer->sale_channels : SaleChannels::getDefault();
|
||||
}
|
||||
|
||||
public static function getSaleChannel()
|
||||
{
|
||||
return SaleChannels::getDefault();
|
||||
@@ -60,7 +81,7 @@ class Customers
|
||||
$filename = self::makeAvatarFilename($customer);
|
||||
$name = $customer->first_name.' '.$customer->last_name;
|
||||
$avatar = new Avatar();
|
||||
|
||||
|
||||
return $avatar->create($name)
|
||||
->setBackground('#F2B90F')
|
||||
->setForeground('#335012')
|
||||
@@ -129,22 +150,25 @@ class Customers
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
$customer = self::get($id, ['delivery_addresses', 'invoice_addresses']);
|
||||
$customer = self::get($id, ['delivery_addresses', 'invoice_addresses', 'sale_channels']);
|
||||
$data = $customer->toArray();
|
||||
$data['deliveries'] = $customer->deliveries->pluck('id')->toArray();
|
||||
$data['sale_channels'] = $customer->sale_channels->pluck('id')->toArray();
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
public static function storeFull($data)
|
||||
{
|
||||
$deliveries = $data['deliveries'];
|
||||
$invoices = $data['invoices'];
|
||||
unset($data['deliveries']);
|
||||
unset($data['invoices']);
|
||||
// $invoices = $data['invoices'];
|
||||
$saleChannels = $data['sale_channels'];
|
||||
// unset($data['invoices']);
|
||||
unset($data['sale_channels']);
|
||||
$customer = self::store($data);
|
||||
self::storeAddresses($customer, $deliveries);
|
||||
self::storeAddresses($customer, $invoices);
|
||||
if ($customer) {
|
||||
// self::storeAddresses($customer->id, $deliveries);
|
||||
// self::storeAddresses($customer->id, $invoices);
|
||||
self::storeSaleChannels($customer->id, $saleChannels);
|
||||
}
|
||||
|
||||
return $customer->id;
|
||||
}
|
||||
@@ -163,31 +187,37 @@ class Customers
|
||||
return $customer->deliveries()->sync($deliveries);
|
||||
}
|
||||
|
||||
public static function storeAddresses($customer, $addresses)
|
||||
public static function storeAddresses($customerId, $addresses)
|
||||
{
|
||||
foreach ($addresses as $address) {
|
||||
$address['customer_id'] = $customer->id;
|
||||
$address['customer_id'] = $customerId;
|
||||
CustomerAddresses::store($address);
|
||||
}
|
||||
}
|
||||
|
||||
public static function storeSaleChannels($customerId, $saleChannels)
|
||||
{
|
||||
$oldSaleChannels = self::getSaleChannelIds($customerId);
|
||||
$deleteSaleChannels = array_diff($oldSaleChannels, $saleChannels);
|
||||
$newSaleChannels = array_diff($saleChannels, $oldSaleChannels);
|
||||
|
||||
$data = ['customer_id' => $customerId];
|
||||
foreach ($newSaleChannels as $saleChannelId) {
|
||||
$data['sale_channel_id'] = $saleChannelId;
|
||||
CustomerSaleChannels::store($data);
|
||||
}
|
||||
foreach ($deleteSaleChannels as $saleChannelId) {
|
||||
CustomerSaleChannels::destroyByCustomerAndSaleChannel($customerId, $saleChannelId);
|
||||
}
|
||||
}
|
||||
|
||||
public static function create($data)
|
||||
{
|
||||
return Customer::create([
|
||||
'uuid' => Str::uuid(),
|
||||
'active' => true,
|
||||
'first_name' => $data['first_name'],
|
||||
'last_name' => $data['last_name'],
|
||||
'company' => $data['company'],
|
||||
'tva' => $data['tva'],
|
||||
'phone' => $data['phone'],
|
||||
'address' => $data['address'],
|
||||
'address2' => $data['address2'],
|
||||
'zipcode' => $data['zipcode'],
|
||||
'city' => $data['city'],
|
||||
'email' => $data['email'],
|
||||
'password' => bcrypt($data['password']),
|
||||
]);
|
||||
$data['uuid'] = Str::uuid();
|
||||
$data['active'] = true;
|
||||
$data['password'] = bcrypt($data['password']);
|
||||
|
||||
return Customer::create($data);
|
||||
}
|
||||
|
||||
public static function getStorage($filename = false)
|
||||
|
||||
@@ -9,6 +9,13 @@ class Deliveries
|
||||
{
|
||||
use Basic;
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return [
|
||||
'sale_channels' => SaleChannels::getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function getSaleChannelId($deliveryId)
|
||||
{
|
||||
return $deliveryId ? Deliveries::getField($deliveryId, 'sale_channel_id') : SaleChannels::getDefaultID();
|
||||
|
||||
@@ -12,7 +12,7 @@ class DeliveryTypeCalculations
|
||||
public static function getPriceByDeliveryType($deliveryTypeId, $weight)
|
||||
{
|
||||
$price = DeliveryTypeCalculation::byDeliveryType($deliveryTypeId)->byWeight($weight)->first();
|
||||
|
||||
|
||||
return $price ? $price->price : false;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use App\Traits\Model\Basic;
|
||||
class InvoicePayments
|
||||
{
|
||||
use Basic;
|
||||
|
||||
|
||||
public static function init()
|
||||
{
|
||||
return [
|
||||
|
||||
@@ -3,8 +3,8 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Merchandise;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Repositories\Core\Tag;
|
||||
use App\Traits\Model\Basic;
|
||||
use App\Traits\Repository\Imageable;
|
||||
|
||||
class Merchandises
|
||||
@@ -68,7 +68,6 @@ class Merchandises
|
||||
return Tag::storeTags($merchandise, $tags);
|
||||
}
|
||||
|
||||
|
||||
public static function getModel()
|
||||
{
|
||||
return Merchandise::query();
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Offer;
|
||||
use App\Models\Shop\PriceList;
|
||||
use App\Traits\Model\Basic;
|
||||
|
||||
class Offers
|
||||
@@ -30,6 +29,7 @@ class Offers
|
||||
{
|
||||
return Offer::with('variation')->byIds($ids)->get();
|
||||
}
|
||||
|
||||
public static function getWithPricesByIds($ids, $saleChannelId = false)
|
||||
{
|
||||
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
|
||||
@@ -69,7 +69,7 @@ class Offers
|
||||
$saleChannelId = $saleChannelId ? $saleChannelId : SaleChannels::getDefaultID();
|
||||
$offer = Offer::withPriceBySaleChannelByQuantity($saleChannelId, $quantity)->find($id);
|
||||
$priceList = $offer->price_lists->first();
|
||||
|
||||
|
||||
return $priceList ? $priceList->price_list_values->first() : false;
|
||||
}
|
||||
|
||||
|
||||
@@ -29,6 +29,7 @@ class Orders
|
||||
$data = $order->toArray();
|
||||
$data['payment_type'] = InvoicePayments::getPaymentType($order->payment_type);
|
||||
$data['status'] = Orders::getStatus($order->status);
|
||||
|
||||
return $data;
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ use App\Traits\Model\Basic;
|
||||
class PriceLists
|
||||
{
|
||||
use Basic;
|
||||
|
||||
|
||||
public static function init($tariffId = false)
|
||||
{
|
||||
return [
|
||||
@@ -47,7 +47,6 @@ class PriceLists
|
||||
return PriceList::byTariff($id)->get();
|
||||
}
|
||||
|
||||
|
||||
public static function edit($id)
|
||||
{
|
||||
$price_list = self::getFull($id)->toArray();
|
||||
|
||||
@@ -2,10 +2,6 @@
|
||||
|
||||
namespace App\Repositories\Shop;
|
||||
|
||||
use App\Models\Shop\Category;
|
||||
use App\Repositories\Core\Categories as CategoryTrees;
|
||||
use App\Repositories\Core\Tag;
|
||||
|
||||
class Shelves
|
||||
{
|
||||
public static function getOffersByCategoryAndNature($categoryId, $articleNatureId = false, $tags = [], $articleNature = false, $displayByRows = false)
|
||||
@@ -29,6 +25,7 @@ class Shelves
|
||||
$productType = ArticleNatures::getProductTypeBySlug($articleNature);
|
||||
$articleNatureId = ArticleNatures::getIdBySlug($articleNature);
|
||||
}
|
||||
|
||||
return [
|
||||
'category' => Categories::getFull($categoryId),
|
||||
'breadcrumb' => Categories::getAncestorsByCategory($categoryId),
|
||||
|
||||
@@ -23,6 +23,7 @@ class Tariffs
|
||||
],
|
||||
];
|
||||
}
|
||||
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Tariff::byAutocomplete($str)->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
|
||||
@@ -17,6 +17,7 @@ class Variations
|
||||
'unities' => Unities::getOptions(),
|
||||
];
|
||||
}
|
||||
|
||||
public static function autocomplete($str)
|
||||
{
|
||||
$data = Variation::where('name', 'LIKE', "%${str}%")->orderBy('name')->limit(30)->get()->pluck('name', 'id');
|
||||
@@ -57,7 +58,6 @@ class Variations
|
||||
return Packages::getName($data['package_id']).' '.$data['quantity'].' '.Unities::getName($data['unity_id']);
|
||||
}
|
||||
|
||||
|
||||
public static function getFull($id)
|
||||
{
|
||||
return Variation::with(['package', 'unity'])->findOrFail($id);
|
||||
|
||||
Reference in New Issue
Block a user