¨4.0.1¨
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Order\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Checkout\Mail\Invoice;
|
||||
use Illuminate\Support\Facades\Mail;
|
||||
@@ -11,8 +12,9 @@ class OrderEmailController
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Modules\Order\Entities\Order $order
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Order $order
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function store(Order $order)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Order\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Order\Entities\Order;
|
||||
|
||||
class OrderPrintController
|
||||
@@ -9,8 +10,9 @@ class OrderPrintController
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*
|
||||
* @param \Modules\Order\Entities\Order $order
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Order $order
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function show(Order $order)
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
|
||||
namespace Modules\Order\Http\Controllers\Admin;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
use Modules\Order\Entities\Order;
|
||||
use Modules\Order\Entities\OrderProduct;
|
||||
use Modules\Order\Events\OrderStatusChanged;
|
||||
@@ -11,8 +12,9 @@ class OrderStatusController
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Modules\Order\Entities\Order $request
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param Order $request
|
||||
*
|
||||
* @return Response
|
||||
*/
|
||||
public function update(Order $order)
|
||||
{
|
||||
@@ -27,6 +29,7 @@ class OrderStatusController
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
private function adjustStock(Order $order)
|
||||
{
|
||||
if ($this->canceledOrRefunded(request('status'))) {
|
||||
@@ -38,36 +41,54 @@ class OrderStatusController
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private function canceledOrRefunded($status)
|
||||
{
|
||||
return in_array($status, [Order::CANCELED, Order::REFUNDED]);
|
||||
}
|
||||
|
||||
|
||||
private function restoreStock(Order $order)
|
||||
{
|
||||
$order->products->each(function (OrderProduct $orderProduct) {
|
||||
if ($orderProduct->product->manage_stock) {
|
||||
$orderProduct->product->increment('qty', $orderProduct->qty);
|
||||
}
|
||||
if ($orderProduct->product_variant) {
|
||||
if ($orderProduct->product_variant->manage_stock) {
|
||||
$orderProduct->product_variant->increment('qty', $orderProduct->qty);
|
||||
}
|
||||
|
||||
if ($orderProduct->product->qty > 0) {
|
||||
$orderProduct->product->markAsInStock();
|
||||
if ($orderProduct->product_variant->qty === 1) {
|
||||
$orderProduct->product_variant->markAsInStock();
|
||||
}
|
||||
} else {
|
||||
if ($orderProduct->product->manage_stock) {
|
||||
$orderProduct->product->increment('qty', $orderProduct->qty);
|
||||
}
|
||||
|
||||
if ($orderProduct->product->qty > 0) {
|
||||
$orderProduct->product->markAsInStock();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private function reduceStock(Order $order)
|
||||
{
|
||||
$order->products->each(function (OrderProduct $orderProduct) {
|
||||
if (
|
||||
$orderProduct->product->manage_stock
|
||||
&& $orderProduct->product->qty !== 0
|
||||
) {
|
||||
$orderProduct->product->decrement('qty', $orderProduct->qty);
|
||||
}
|
||||
|
||||
if ($orderProduct->product->qty === 0) {
|
||||
$orderProduct->product->markAsOutOfStock();
|
||||
if ($orderProduct->product_variant) {
|
||||
if (
|
||||
$orderProduct->product_variant->manage_stock
|
||||
&& $orderProduct->product_variant->qty !== 0
|
||||
) {
|
||||
$orderProduct->product_variant->decrement('qty', $orderProduct->qty);
|
||||
}
|
||||
} else {
|
||||
if (
|
||||
$orderProduct->product->manage_stock
|
||||
&& $orderProduct->product->qty !== 0
|
||||
) {
|
||||
$orderProduct->product->decrement('qty', $orderProduct->qty);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2,22 +2,25 @@
|
||||
|
||||
namespace Modules\Order\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class OrderController
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
return view('order::index');
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function show()
|
||||
{
|
||||
|
||||
@@ -2,10 +2,13 @@
|
||||
|
||||
namespace Modules\Order\Http\Requests;
|
||||
|
||||
use Exception;
|
||||
use Modules\Support\Country;
|
||||
use Modules\Cart\Facades\Cart;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Modules\Payment\Facades\Gateway;
|
||||
use Modules\Core\Http\Requests\Request;
|
||||
use Modules\Checkout\Http\Exceptions\CheckoutException;
|
||||
|
||||
class StoreOrderRequest extends Request
|
||||
{
|
||||
@@ -16,16 +19,54 @@ class StoreOrderRequest extends Request
|
||||
*/
|
||||
protected $availableAttributes = 'checkout::attributes';
|
||||
|
||||
|
||||
/**
|
||||
* Validate the class instance.
|
||||
*
|
||||
* @return void
|
||||
* @throws Exception
|
||||
*/
|
||||
public function prepareForValidation()
|
||||
{
|
||||
if (!Cart::allItemsAreVirtual() && !$this->input('shipping_method')) {
|
||||
throw new CheckoutException(trans('checkout::messages.no_shipping_method'));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get the validation rules that apply to the request.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function rules()
|
||||
{
|
||||
return array_merge(
|
||||
[
|
||||
'customer_email' => ['required', 'email', $this->emailUniqueRule()],
|
||||
'customer_phone' => ['required'],
|
||||
'create_an_account' => 'boolean',
|
||||
'password' => 'required_if:create_an_account,1',
|
||||
'ship_to_a_different_address' => 'boolean',
|
||||
'payment_method' => ['required', Rule::in(Gateway::names())],
|
||||
'terms_and_conditions' => 'accepted',
|
||||
'shipping_method' => Cart::allItemsAreVirtual() ? 'nullable' : 'required',
|
||||
],
|
||||
$this->billingAddressRules(),
|
||||
$this->shippingAddressRules()
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
private function emailUniqueRule()
|
||||
{
|
||||
return $this->create_an_account ? Rule::unique('users', 'email') : null;
|
||||
}
|
||||
|
||||
|
||||
private function billingAddressRules()
|
||||
{
|
||||
return [
|
||||
'customer_email' => ['required', 'email', $this->emailUniqueRule()],
|
||||
'customer_phone' => ['required'],
|
||||
'billing.first_name' => 'required',
|
||||
'billing.last_name' => 'required',
|
||||
'billing.address_1' => 'required',
|
||||
@@ -33,9 +74,13 @@ class StoreOrderRequest extends Request
|
||||
'billing.zip' => 'required',
|
||||
'billing.country' => ['required', Rule::in(Country::supportedCodes())],
|
||||
'billing.state' => 'required',
|
||||
'create_an_account' => 'boolean',
|
||||
'password' => 'required_if:create_an_account,1',
|
||||
'ship_to_a_different_address' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
private function shippingAddressRules()
|
||||
{
|
||||
return [
|
||||
'shipping.first_name' => 'required_if:ship_to_a_different_address,1',
|
||||
'shipping.last_name' => 'required_if:ship_to_a_different_address,1',
|
||||
'shipping.address_1' => 'required_if:ship_to_a_different_address,1',
|
||||
@@ -43,13 +88,6 @@ class StoreOrderRequest extends Request
|
||||
'shipping.zip' => 'required_if:ship_to_a_different_address,1',
|
||||
'shipping.country' => ['required_if:ship_to_a_different_address,1', Rule::in(Country::supportedCodes())],
|
||||
'shipping.state' => 'required_if:ship_to_a_different_address,1',
|
||||
'payment_method' => ['required', Rule::in(Gateway::names())],
|
||||
'terms_and_conditions' => 'accepted',
|
||||
];
|
||||
}
|
||||
|
||||
private function emailUniqueRule()
|
||||
{
|
||||
return $this->create_an_account ? Rule::unique('users', 'email') : null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user