Order creation

This commit is contained in:
jitendra 2018-10-04 12:12:06 +05:30
commit c235c22e79
27 changed files with 1052 additions and 3415 deletions

View File

@ -371,8 +371,6 @@ class Cart {
if($data['is_configurable'] == "true") {
$parent = $cart->items()->create($itemData['parent']);
$this->canAddOrUpdate($parent->child->id, $parent->quantity);
$itemData['child']['parent_id'] = $parent->id;
// $this->canAddOrUpdate($parent->child->id, $parent->quantity);
@ -505,30 +503,21 @@ class Cart {
{
$data = [];
if(is_array($item->additional) && isset($item->additional['super_attribute'])) {
foreach($item->additional['super_attribute'] as $attributeId => $optionId) {
$option = $attribute->options()->where('id', $optionId)->first();
dd($option);
}
}
$labels = [];
foreach($item->product->super_attributes as $attribute) {
// dd($item->child);
// dd($attribute->options);
// dd($attribute->code);
dd($item->child->product->{$attribute->code});
$option = $attribute->options()->where('id', $item->child->{$attribute->code})->first();
dd($option);
$option = $attribute->options()->where('id', $item->child->product->{$attribute->code})->first();
$data['attributes'][$attribute->code] = [
'attribute_name' => $attribute->name,
'option_label' => $option->label,
];
dd($data);
$labels[] = $attribute->name . ' : ' . $option->label;
}
$data['html'] = implode(', ', $labels);
return $data;
}

View File

@ -8,10 +8,40 @@ use Webkul\Core\Models\Locale as LocaleModel;
use Webkul\Core\Models\Currency as CurrencyModel;
use Webkul\Core\Models\TaxCategory as TaxCategory;
use Webkul\Core\Models\TaxRate as TaxRate;
use Webkul\Core\Repositories\CurrencyRepository;
use Webkul\Core\Repositories\ExchangeRateRepository;
use Illuminate\Support\Facades\Config;
class Core
{
/**
* CurrencyRepository model
*
* @var mixed
*/
protected $currencyRepository;
/**
* ExchangeRateRepository model
*
* @var mixed
*/
protected $exchangeRateRepository;
/**
* Create a new instance.
*
* @param Webkul\Core\Repositories\CurrencyRepository $currencyRepository
* @param Webkul\Core\Repositories\ExchangeRateRepository $exchangeRateRepository
* @return void
*/
public function __construct(CurrencyRepository $currencyRepository, ExchangeRateRepository $exchangeRateRepository)
{
$this->currencyRepository = $currencyRepository;
$this->exchangeRateRepository = $exchangeRateRepository;
}
/**
* Returns all channels
*
@ -83,6 +113,53 @@ class Core
return $currencies = CurrencyModel::all();
}
/**
* Returns base channel's currency model
*
* @return mixed
*/
public function getBaseCurrency()
{
static $currency;
if($currency)
return $currency;
$currenctChannel = $this->getCurrentChannel();
return $currency = $currenctChannel->base_currency;
}
/**
* Returns base channel's currency code
*
* @return string
*/
public function getBaseCurrencyCode()
{
static $currencyCode;
if($currencyCode)
return $currencyCode;
return ($currency = $this->getBaseCurrency()) ? $currencyCode = $currency->code : '';
}
/**
* Returns base channel's currency symbol
*
* @return string
*/
public function getBaseCurrencySymbol()
{
static $currencySymbol;
if($currencySymbol)
return $currencySymbol;
return $currencySymbol = $this->getCurrentCurrency()->symbol;
}
/**
* Returns current channel's currency model
*
@ -134,9 +211,34 @@ class Core
* @param float $price
* @return string
*/
public function convertPrice($price, $currencyCode = null)
public function convertPrice($amount, $sourceCurrencyCode = null, $targetCurrencyCode = null)
{
return $price;
$sourceCurrency = !$sourceCurrencyCode
? $this->getBaseCurrency()
: $this->currencyRepository->findByField('code', $sourceCurrencyCode);
$targetCurrency = !$targetCurrencyCode
? $this->getCurrentCurrency()
: $this->currencyRepository->findByField('code', $targetCurrencyCode);
if(!$sourceCurrency || !$sourceCurrency)
return $amount;
if ($sourceCurrency->code === $targetCurrency->code)
return $amount;
$exchangeRate = $this->exchangeRateRepository->findOneWhere([
'source_currency' => $sourceCurrency->id,
'target_currency' => $targetCurrency->id,
]);
if (null === $exchangeRate)
return $amount;
if ($exchangeRate->source_currency->code === $sourceCurrencyCode)
return (float) round($amount * $exchangeRate->ratio);
return (float) round($amount / $exchangeRate->ratio);
}
/**
@ -145,16 +247,11 @@ class Core
* @param float $price
* @return string
*/
public function currency($price)
public function currency($amount = 0)
{
if(!$price)
$price = 0;
$currencyCode = $this->getCurrentCurrency()->code;
$channel = $this->getCurrentChannel();
$currencyCode = $channel->base_currency->code;
return currency($price, $currencyCode);
return currency($this->convertPrice($amount), $currencyCode);
}
/**

View File

@ -4,7 +4,7 @@
if (! function_exists('core')) {
function core()
{
return new Core;
return app()->make(Core::class);
}
}

View File

@ -52,8 +52,9 @@ class CoreServiceProvider extends ServiceProvider
{
$loader = AliasLoader::getInstance();
$loader->alias('core', CoreFacade::class);
$this->app->singleton('core', function () {
return new Core();
return app()->make(Core::class);
});
}
}

View File

@ -0,0 +1,7 @@
<?php
namespace Webkul\Sales\Contracts;
interface OrderPayment
{
}

View File

@ -0,0 +1,35 @@
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreateOrderPaymentTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('order_payment', function (Blueprint $table) {
$table->increments('id');
$table->string('method');
$table->string('method_title')->nullable();
$table->integer('order_id')->nullable()->unsigned();
$table->foreign('order_id')->references('id')->on('orders');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('order_payment');
}
}

View File

@ -46,6 +46,14 @@ class Order extends Model implements OrderContract
return $this->hasMany(OrderAddressProxy::modelClass());
}
/**
* Get the payment for the order.
*/
public function payment()
{
return $this->hasMany(OrderPaymentProxy::modelClass());
}
/**
* Get the biling address for the order.
*/

View File

@ -0,0 +1,12 @@
<?php
namespace Webkul\Sales\Models;
use Illuminate\Database\Eloquent\Model;
use Webkul\Sales\Contracts\OrderPayment as OrderPaymentContract;
class OrderPayment extends Model implements OrderPaymentContract
{
protected $table = 'order_payment';
}

View File

@ -0,0 +1,10 @@
<?php
namespace Webkul\Sales\Models;
use Konekt\Concord\Proxies\ModelProxy;
class OrderPaymentProxy extends ModelProxy
{
}

View File

@ -7,9 +7,10 @@ use Konekt\Concord\BaseModuleServiceProvider;
class ModuleServiceProvider extends BaseModuleServiceProvider
{
protected $models = [
\Webkul\Sales\Models\OrderAddress::class,
\Webkul\Sales\Models\Order::class,
\Webkul\Sales\Models\OrderItem::class,
\Webkul\Sales\Models\OrderAddress::class,
\Webkul\Sales\Models\OrderPayment::class,
\Webkul\Sales\Models\Invoice::class,
\Webkul\Sales\Models\InvoiceItem::class,
\Webkul\Sales\Models\Shipment::class,

View File

@ -4,6 +4,8 @@ namespace Webkul\Sales\Repositories;
use Illuminate\Container\Container as App;
use Webkul\Core\Eloquent\Repository;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Facades\DB;
/**
* Order Reposotory
@ -54,8 +56,25 @@ class OrderRepository extends Repository
*/
public function create(array $data)
{
$order = $this->find(2);
$this->validateOrder();
dd($order->customer);
DB::beginTransaction();
try {
Event::fire('checkout.order.save.before', $data);
$order = null;
} catch (\Exception $e) {
DB::rollBack();
throw $e;
}
DB::commit();
Event::fire('checkout.order.save.after', $order);
return $order;
}
}

View File

@ -9,6 +9,7 @@ use Webkul\Checkout\Facades\Cart;
use Webkul\Shipping\Facades\Shipping;
use Webkul\Payment\Facades\Payment;
use Webkul\Checkout\Http\Requests\CustomerAddressForm;
use Webkul\Sales\Repositories\OrderRepository;
/**
* Chekout controller for the customer and guest for placing order
@ -18,6 +19,13 @@ use Webkul\Checkout\Http\Requests\CustomerAddressForm;
*/
class OnepageController extends Controller
{
/**
* OrderRepository object
*
* @var array
*/
protected $orderRepository;
/**
* Contains route related configuration
*
@ -28,10 +36,13 @@ class OnepageController extends Controller
/**
* Create a new controller instance.
*
* @param Webkul\Attribute\Repositories\OrderRepository $orderRepository
* @return void
*/
public function __construct()
public function __construct(OrderRepository $orderRepository)
{
$this->orderRepository = $orderRepository;
$this->_config = request('_config');
}
@ -98,4 +109,46 @@ class OnepageController extends Controller
'html' => view('shop::checkout.onepage.review', compact('cart'))->render()
]);
}
/**
* Saves order.
*
* @return \Illuminate\Http\Response
*/
public function saveOrder()
{
Cart::collectTotals();
$this->validateOrder();
$order = $this->orderRepository->create([]);
session()->flash('order', $order);
return response()->json([
'success' => true
]);
}
/**
* Order success page
*
* @return \Illuminate\Http\Response
*/
public function success()
{
if(!$order = session('order'))
return redirect()->route('shop.checkout.cart.index');
return view($this->_config['view'], compact('order'));
}
/**
* Validate order before creation
*
* @return mixed
*/
public function validateOrder()
{
}
}

View File

@ -18,11 +18,17 @@ Route::group(['middleware' => ['web']], function () {
'view' => 'shop::checkout.onepage'
])->name('shop.checkout.onepage.index');
Route::post('/checkout/save-address', 'Webkul\Shop\Http\Controllers\CheckoutController@saveAddress')->name('shop.checkout.save-address');
Route::post('/checkout/save-address', 'Webkul\Shop\Http\Controllers\OnepageController@saveAddress')->name('shop.checkout.save-address');
Route::post('/checkout/save-shipping', 'Webkul\Shop\Http\Controllers\CheckoutController@saveShipping')->name('shop.checkout.save-shipping');
Route::post('/checkout/save-shipping', 'Webkul\Shop\Http\Controllers\OnepageController@saveShipping')->name('shop.checkout.save-shipping');
Route::post('/checkout/save-payment', 'Webkul\Shop\Http\Controllers\CheckoutController@savePayment')->name('shop.checkout.save-payment');
Route::post('/checkout/save-payment', 'Webkul\Shop\Http\Controllers\OnepageController@savePayment')->name('shop.checkout.save-payment');
Route::post('/checkout/save-order', 'Webkul\Shop\Http\Controllers\OnepageController@saveOrder')->name('shop.checkout.save-order');
Route::get('/checkout/success', 'Webkul\Shop\Http\Controllers\OnepageController@success')->defaults('_config', [
'view' => 'shop::checkout.success'
])->name('shop.checkout.success');
Route::get('test', 'Webkul\Shop\Http\Controllers\CartController@test');

File diff suppressed because it is too large Load Diff

View File

@ -0,0 +1,57 @@
// product card, requires no changes for responsiveness.
.product-card {
.product-image {
max-height: 350px;
max-width: 280px;
margin-bottom: 10px;
background: #F2F2F2;
img {
display: block;
width: 100%;
}
}
.product-name {
margin-bottom: 14px;
width: 100%;
color: $font-color;
a {
color: $font-color;
}
}
.product-description {
margin-bottom: 14px;
display: none;
}
.product-ratings {
width: 100%;
margin-bottom: 14px;
.icon {
width: 16px;
height: 16px;
}
.total-reviews {
display: none;
}
}
.cart-fav-seg {
display: inline-flex;
width: 100%;
align-items: center;
.addtocart {
border-radius: 0px;
margin-right: 10px;
text-transform: uppercase;
white-space: nowrap;
}
}
}

View File

@ -0,0 +1,69 @@
body {
margin: 0;
padding: 0;
font-weight: 500;
max-width: 100%;
width: auto;
color: $font-color;
font-size: $font-size-base;
}
* {
font-family: "Montserrat", sans-serif;
}
.btn.btn-primary{
border-radius: 0px;
}
.mb-10 {
margin-bottom: 10px;
}
.mb-15 {
margin-bottom: 15px;
}
.mb-20 {
margin-bottom: 20px;
}
.mb-25 {
margin-bottom: 25px;
}
.mb-30 {
margin-bottom: 30px;
}
.mb-35 {
margin-bottom: 35px;
}
.mb-40 {
margin-bottom: 40px;
}
.mb-45 {
margin-bottom: 45px;
}
.mb-50 {
margin-bottom: 50px;
}
.mb-60 {
margin-bottom: 60px;
}
.mb-70 {
margin-bottom: 70px;
}
.mb-80 {
margin-bottom: 80px;
}
.mb-90 {
margin-bottom: 90px;
}

View File

@ -1,6 +1,10 @@
<?php
return [
'common' => [
'error' => 'Something went wrong, please contact us or try again later.'
],
'customer' => [
'signup-text' => [
'account_exists' => 'Already have an account',

View File

@ -19,7 +19,7 @@
<div class="cart-content">
<div class="left-side">
<form action="{{ route('shop.checkout.cart.update') }}" method="POST">
<form action="{{ route('shop.checkout.cart.update') }}" method="POST" @submit.prevent="onSubmit">
<div class="cart-item-list" style="margin-top: 0">
@csrf
@ -49,15 +49,13 @@
@if ($product->type == 'configurable')
<div class="summary">
@foreach (cart::getItemAttributeOptionDetails($item) as $key => $option)
{{ (!$key ? '' : ' , ') . $option['attribute_name'] . ' : ' . $option['option_label'] }}
{{ Cart::getItemAttributeOptionDetails($item)['html'] }}
@endforeach
</div>
@endif
<div class="misc">
<div class="misc" :class="[errors.has('quantity') ? 'has-error' : '']">
<div class="qty-text">{{ __('shop::app.checkout.cart.quantity') }}</div>
{{-- <div class="box">{{ $item->quantity }}</div> --}}
<input class="box" type="text" v-validate="'required|numeric|min_value:1'" name="qty[{{$item->id}}]" value="{{ $item->quantity }}">

View File

@ -45,7 +45,7 @@
<div class="button-group">
<button type="button" class="btn btn-lg btn-primary" @click="validateForm('address-form')">
<button type="button" class="btn btn-lg btn-primary" @click="validateForm('address-form')" :disabled="disable_button">
{{ __('shop::app.checkout.onepage.continue') }}
</button>
@ -59,7 +59,7 @@
<div class="button-group">
<button type="button" class="btn btn-lg btn-primary" @click="validateForm('shipping-form')">
<button type="button" class="btn btn-lg btn-primary" @click="validateForm('shipping-form')" :disabled="disable_button">
{{ __('shop::app.checkout.onepage.continue') }}
</button>
@ -73,7 +73,7 @@
<div class="button-group">
<button type="button" class="btn btn-lg btn-primary" @click="validateForm('payment-form')">
<button type="button" class="btn btn-lg btn-primary" @click="validateForm('payment-form')" :disabled="disable_button">
{{ __('shop::app.checkout.onepage.continue') }}
</button>
@ -87,7 +87,7 @@
<div class="button-group">
<button type="button" class="btn btn-lg btn-primary" @click="placeOrder()">
<button type="button" class="btn btn-lg btn-primary" @click="placeOrder()" :disabled="disable_button">
{{ __('shop::app.checkout.onepage.place-order') }}
</button>
@ -134,6 +134,8 @@
selected_shipping_method: '',
selected_payment_method: '',
disable_button: false,
}),
methods: {
@ -160,8 +162,13 @@
saveAddress () {
var this_this = this;
this.disable_button = true;
this.$http.post("{{ route('shop.checkout.save-address') }}", this.address)
.then(function(response) {
this_this.disable_button = false;
if(response.data.jump_to_section == 'shipping') {
shippingHtml = Vue.compile(response.data.html)
this_this.completedStep = 1;
@ -169,14 +176,21 @@
}
})
.catch(function (error) {
this_this.disable_button = false;
this_this.handleErrorResponse(error.response, 'address-form')
})
},
saveShipping () {
var this_this = this;
this.disable_button = true;
this.$http.post("{{ route('shop.checkout.save-shipping') }}", {'shipping_method': this.selected_shipping_method})
.then(function(response) {
this_this.disable_button = false;
if(response.data.jump_to_section == 'payment') {
paymentHtml = Vue.compile(response.data.html)
this_this.completedStep = 2;
@ -184,14 +198,21 @@
}
})
.catch(function (error) {
this_this.disable_button = false;
this_this.handleErrorResponse(error.response, 'shipping-form')
})
},
savePayment () {
var this_this = this;
this.disable_button = true;
this.$http.post("{{ route('shop.checkout.save-payment') }}", {'payment': this.selected_payment_method})
.then(function(response) {
this_this.disable_button = false;
if(response.data.jump_to_section == 'review') {
reviewHtml = Vue.compile(response.data.html)
this_this.completedStep = 3;
@ -199,12 +220,34 @@
}
})
.catch(function (error) {
this_this.disable_button = false;
this_this.handleErrorResponse(error.response, 'payment-form')
})
},
placeOrder () {
var this_this = this;
this.disable_button = true;
this.$http.post("{{ route('shop.checkout.save-order') }}", {'_token': "{{ csrf_token() }}"})
.then(function(response) {
if(response.data.success) {
if(response.data.redirect_url) {
window.location.href = response.data.redirect_url;
} else {
window.location.href = "{{ route('shop.checkout.success') }}";
}
}
})
.catch(function (error) {
this_this.disable_button = true;
window.flashMessages = [{'type': 'alert-error', 'message': "{{ __('shop::app.common.error') }}" }];
this_this.$root.addFlashMessages()
})
},
handleErrorResponse (response, scope) {

View File

@ -86,11 +86,9 @@
@if ($product->type == 'configurable')
<div class="summary" >
@foreach (cart()->getItemAttributeOptionDetails($item) as $key => $option)
{{ (!$key ? '' : ' , ') . $option['attribute_name'] . ' : ' . $option['option_label'] }}
{{ Cart::getItemAttributeOptionDetails($item)['html'] }}
@endforeach
</div>
@endif
</div>

View File

@ -4,7 +4,7 @@
<span class="featured-seperator" style="color:lightgrey;">_____</span>
</div>
<div class="featured-grid product-grid max-4-col">
<div class="featured-grid product-grid-4">
<div class="product-card">
<div class="product-image">
<img src="vendor/webkul/shop/assets/images/grid.png" />

View File

@ -4,7 +4,7 @@
<span class="featured-seperator" style="color:lightgrey;">_____</span>
</div>
<div class="new-product-grid product-grid max-4-col">
<div class="new-product-grid product-grid-4">
<div class="product-card">
<div class="product-image">
<img src="vendor/webkul/shop/assets/images/new.png" />

View File

@ -2,46 +2,54 @@
@section('content-wrapper')
@include ('shop::products.list.layered-navigation')
@inject ('productRepository', 'Webkul\Product\Repositories\ProductRepository')
<div class="main" style="display: inline-block">
<div class="main">
@inject ('productRepository', 'Webkul\Product\Repositories\ProductRepository')
<div class="category-block">
@include ('shop::products.list.layered-navigation')
<?php $products = $productRepository->findAllByCategory($category->id); ?>
<div class="category-block">
@include ('shop::products.list.toolbar')
<div class="hero-image mb-15">
<img src="https://images.pexels.com/photos/428338/pexels-photo-428338.jpeg?cs=srgb&dl=adolescent-casual-cute-428338.jpg&fm=jpg" />
</div>
@inject ('toolbarHelper', 'Webkul\Product\Product\Toolbar')
<?php $products = $productRepository->findAllByCategory($category->id); ?>
@if ($toolbarHelper->getCurrentMode() == 'grid')
<div class="product-grid max-3-col">
@include ('shop::products.list.toolbar')
@foreach ($products as $product)
@inject ('toolbarHelper', 'Webkul\Product\Product\Toolbar')
@include ('shop::products.list.card', ['product' => $product])
@if ($toolbarHelper->getCurrentMode() == 'grid')
<div class="product-grid-3">
@endforeach
@foreach ($products as $product)
@include ('shop::products.list.card', ['product' => $product])
@endforeach
</div>
@else
<div class="product-list">
@foreach ($products as $product)
@include ('shop::products.list.card', ['product' => $product])
@endforeach
</div>
@endif
<div class="bottom-toolbar">
{{ $products->appends(request()->input())->links() }}
</div>
</div>
@else
<div class="product-list">
@foreach ($products as $product)
@include ('shop::products.list.card', ['product' => $product])
@endforeach
</div>
@endif
<div class="bottom-toolbar">
{{ $products->appends(request()->input())->links() }}
</div>
</div>
@stop

View File

@ -22,9 +22,7 @@
</filter-attribute-item>
</div>
</div>
</div>
</script>

View File

@ -1,6 +1,6 @@
@inject ('toolbarHelper', 'Webkul\Product\Product\Toolbar')
<div class="top-toolbar">
<div class="top-toolbar mb-35">
<div class="page-info">
<span>

File diff suppressed because it is too large Load Diff