Merge branch 'master' of https://github.com/bagisto/bagisto into development

This commit is contained in:
Prashant Singh 2019-03-14 11:01:04 +05:30
commit 5fc85dffe4
53 changed files with 1365 additions and 1209 deletions

View File

@ -1,125 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Customer;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Webkul\Customer\Repositories\CustomerAddressRepository as CustomerAddress;
use Auth;
use Cart;
use Validator;
/**
* Address controller for the APIs Customer Address
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class AddressController extends Controller
{
protected $customer;
protected $customerAddress;
public function __construct(CustomerAddress $customerAddress)
{
$this->middleware('auth:customer');
$this->customerAddress = $customerAddress;
if (auth()->guard('customer')->check()) {
$this->customer = auth()->guard('customer')->user();
} else {
$this->customer['message'] = 'unauthorized';
$this->unAuthorized();
}
}
public function unAuthorized() {
return response()->json($this->customer, 401);
}
/**
* To get the details of user to display on profile
*
* @return response JSON
*/
public function get() {
if ($this->customer == false) {
return response()->json($this->customer, 401);
} else {
$addresses = $this->customer->addresses;
return response()->json($addresses, 200);
}
}
public function getDefault() {
if ($this->customer == false) {
return response()->json($this->customer, 401);
} else {
$defaultAddress = $this->customer->default_address;
if ($defaultAddress->count() > 0) {
return response()->json($defaultAddress, 200);
} else {
return response()->json(['false, default address not found'], 200);
}
}
}
public function create() {
$data = request()->all();
$validator = Validator::make(request()->all(), [
'address1' => 'string|required',
'country' => 'string|required',
'state' => 'string|required',
'city' => 'string|required',
'postcode' => 'required',
'phone' => 'required'
]);
if ($validator->fails()) {
return response()->json($validator->messages(), 400);
}
$cust_id['customer_id'] = $this->customer->id;
$data = array_merge($cust_id, $data);
if ($this->customer->addresses->count() == 0) {
$data['default_address'] = 1;
}
$result = $this->customerAddress->create($data);
if ($result) {
return response()->json(true, 200);
} else {
return response()->json(false, 200);
}
}
public function delete($id) {
$result = $this->customerAddress->delete($id);
return response()->json($result, 200);
}
public function makeDefault($id) {
$defaultAddress = $this->customer->default_address;
if ($defaultAddress != null && $defaultAddress->count() > 0) {
$defaultAddress->update(['default_address' => 0]);
}
if ($this->customerAddress->find($id)->default_address == 1) {
return response()->json(false, 200);
}
$result = $this->customerAddress->update(['default_address' => 1], $id);
return response()->json($result, 200);
}
}

View File

@ -1,44 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Customer;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
// use Webkul\Customer\Http\Listeners\CustomerEventsHandler;
use Auth;
use Cart;
/**
* Session controller for the APIs of user customer
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class AuthController extends Controller
{
/**
* To get the details of user to display on profile
*
* @return response JSON
*/
public function create() {
$data = request()->except('_token');
if (! auth()->guard('customer')->check()) {
if (! auth()->guard('customer')->attempt($data)) {
return response()->json(['message' => 'unauthenticated', 'details' => 'invalid creds'], 401);
} else {
return response()->json(['message' => 'authenticated', 'user' => auth()->guard('customer')->user()], 200);
}
} else {
return response()->json(['message' => 'already authenticated'], 200);
}
}
public function destroy() {
auth()->guard('customer')->logout();
return response()->json(['message' => 'logged out'], 200);
}
}

View File

@ -1,116 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Customer;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Auth;
use Cart;
use Validator;
use Hash;
/**
* Customer controller for the APIs of Profile customer
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CustomerController extends Controller
{
protected $customer;
public function __construct()
{
if (auth()->guard('customer')->check()) {
$this->customer = auth()->guard('customer')->user();
} else {
$this->customer['message'] = 'unauthorized';
$this->unAuthorized();
}
}
public function unAuthorized() {
return response()->json($this->customer, 401);
}
/**
* To get the details of user to display on profile
* Only accepts the id of simple or configurable product
*
* @return response JSON
*/
public function getProfile()
{
return response()->json($this->customer, 200);
}
public function updateProfile($id)
{
$validator = Validator::make(request()->all(), [
'first_name' => 'string|required',
'last_name' => 'string|required',
'gender' => 'required',
'date_of_birth' => 'date',
'email' => 'email|required|unique:customers,email,'.$id,
'password' => 'confirmed|required_if:oldpassword,!=,null'
]);
if ($validator->fails()) {
return response()->json($validator->messages(), 400);
}
$data = collect(request()->all())->toArray();
if ($data['oldpassword'] == null) {
$data = collect(request()->input())->except([ 'oldpassword', 'password', 'password_confirmation'])->toArray();
} else {
if (Hash::check($data['oldpassword'], auth()->guard('customer')->user()->password)) {
$data = collect(request()->input())->toArray();
$data['password'] = bcrypt($data['password']);
} else {
return response()->json('Old password does not match', 200);
}
}
$result = $this->customer->update($data);
if ($result) {
return response()->json(true, 200);
} else {
return response()->json(false, 200);
}
}
/**
* Get all instances of cart for currently logged in customer
*
* @return collection Cart
*/
public function getAllCart() {
$carts = $this->customer->carts;
if ($cart->count() > 0) {
return response()->json(['message' => 'successful','items' => $cart], 200);
} else {
return response()->json(['message' => 'empty', 'items' => null], 200);
}
}
public function getActiveCart() {
$cart = Cart::getCart();
if ($cart == null) {
return response()->json(['message' => 'empty', 'items' => 'null']);
}
if ($cart->count() > 0 ) {
return response()->json(['message' => 'success', 'items' => $cart]);
} else {
return response()->json(['message' => 'empty', 'items' => 'null']);
}
}
}

View File

@ -1,55 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Customer;
use Webkul\API\Http\Controllers\Controller;
use Webkul\Customer\Repositories\CustomerRepository as Customer;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Validator;
/**
* Registration controller for the APIs of Customer Registration
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class RegistrationController extends Controller
{
protected $customer;
public function __construct(Customer $customer) {
$this->customer = $customer;
}
public function create() {
$validator = Validator::make(request()->all(), [
'first_name' => 'string|required',
'last_name' => 'string|required',
'email' => 'email|required|unique:customers,email',
'password' => 'confirmed|min:6|required',
'agreement' => 'required'
]);
if ($validator->fails()) {
return response()->json($validator->messages(), 400);
}
$data = request()->all();
$data['password'] = bcrypt($data['password']);
$data['channel_id'] = core()->getCurrentChannel()->id;
$data['is_verified'] = 0;
$result = $this->customer->create($data);
if ($result) {
return response()->json(true, 200);
} else {
return response()->json(false, 200);
}
}
}

View File

@ -1,102 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Customer;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Product\Repositories\ProductRepository as Product;
use Webkul\Customer\Repositories\WishlistRepository as Wishlist;
use Auth;
use Cart;
/**
* Wishlist controller for the APIs of User's Wishlist
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class WishlistController extends Controller
{
protected $customer;
protected $product;
protected $wishlist;
public function __construct(Product $product, Wishlist $wishlist)
{
if (auth()->guard('customer')->check()) {
$this->product = $product;
$this->wishlist = $wishlist;
$this->customer = auth()->guard('customer')->user();
} else {
$this->customer['message'] = 'unauthorized';
$this->unAuthorized();
}
}
public function unAuthorized()
{
return response()->json($this->customer, 401);
}
public function getWishlist()
{
$wishlist = $this->customer->wishlist_items;
if ($wishlist->count() > 0) {
return response()->json($wishlist, 200);
} else {
return response()->json(['message' => 'Wishlist Empty', 'Items' => null], 200);
}
}
/**
* Function to add item to the wishlist.
* Only accepts the id of simple or configurable product
*
* @param integer $productId
*/
public function add($productId)
{
$product = $this->product->findOneByField('id', $productId);
$data = [
'channel_id' => core()->getCurrentChannel()->id,
'product_id' => $productId,
'customer_id' => auth()->guard('customer')->user()->id
];
//accidental case if some one adds id of the product in the anchor tag amd gives id of a variant.
if ($product->parent_id != null) {
$data['product_id'] = $productId = $product->parent_id;
}
$checked = $this->wishlist->findWhere(['channel_id' => core()->getCurrentChannel()->id, 'product_id' => $productId, 'customer_id' => auth()->guard('customer')->user()->id]);
if ($checked->isEmpty()) {
if ($wishlistItem = $this->wishlist->create($data)) {
return response()->json(['message' => 'Successfully Added Item To Wishlist', 'items' => $wishlistItem], 200);
} else {
return response()->json(['message' => 'Error! Cannot Add Item To Wishlist', 'items' => null], 401);
}
} else {
return response()->json(['message' => trans('customer::app.wishlist.already'), 'items' => null], 200);
}
}
/**
* Function to remove item to the wishlist.
*
* @param integer $itemId
*/
public function delete($itemId)
{
$result = $this->wishlist->deleteWhere(['customer_id' => auth()->guard('customer')->user()->id, 'channel_id' => core()->getCurrentChannel()->id, 'id' => $itemId]);
if ($result) {
return response()->json(['message' => 'Item Successfully Removed From Wishlist', 'status' => $result]);
} else {
return response()->json(['message' => 'Error! While Removing Item From Wishlist', 'status' => $result]);
}
}
}

View File

@ -1,75 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Product;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Product\Repositories\ProductRepository as Product;
/**
* Product controller
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductController extends Controller
{
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
/**
* ProductRepository object
*
* @var array
*/
protected $product;
/**
* Create a new controller instance.
*
* @param Webkul\Product\Repositories\ProductRepository $product
* @return void
*/
public function __construct( Product $product)
{
$this->product = $product;
$this->_config = request('_config');
}
/**
* Display a listing of the resource.
*
* @param string $slug
* @return \Illuminate\Http\Response
*/
public function getBySlug($slug)
{
$product = $this->product->findBySlugOrFail($slug);
return response()->json(['message' => 'success', 'product' => $product]);
}
public function getAll() {
$products = $this->product->all();
return response()->json($products, 200);
}
public function getNew() {
$newProducts = $this->product->getNewProducts();
return response()->json($newProducts, 200);
}
public function getFeatured() {
$featuredProducts = $this->product->getFeaturedProducts();
return response()->json($featuredProducts, 200);
}
}

View File

@ -1,127 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Product;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Product\Repositories\ProductRepository as Product;
use Webkul\Product\Repositories\ProductReviewRepository as ProductReview;
use Webkul\Product\Helpers\Review;
use Validator;
/**
* Review controller
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ReviewController extends Controller
{
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
/**
* ProductRepository object
*
* @var array
*/
protected $product;
/**
* ProductReviewRepository object
*
* @var array
*/
protected $productReview;
/**
* Review helper Object
*
*/
protected $reviewHelper;
/**
* Create a new controller instance.
*
* @param Webkul\Product\Repositories\ProductRepository $product
* @param Webkul\Product\Repositories\ProductReviewRepository $productReview
* @return void
*/
public function __construct(Product $product, ProductReview $productReview, Review $reviewHelper)
{
// $this->middleware('customer')->only(['create', 'store', 'destroy']);
$this->product = $product;
$this->productReview = $productReview;
$this->reviewHelper = $reviewHelper;
$this->_config = request('_config');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $request , $id)
{
$this->validate(request(), [
'comment' => 'required',
'rating' => 'required',
'title' => 'required',
]);
$data = request()->all();
$customer_id = auth()->guard('customer')->user()->id;
$data['status'] = 'pending';
$data['product_id'] = $id;
$data['customer_id'] = $customer_id;
$result = $this->productReview->create($data);
if ($result) {
return response()->json(['message' => 'success', 'status' => $result]);
} else {
return response()->json(['message' => 'failed', 'status' => $result]);
}
}
/**
* Display reviews accroding to product.
*
* @param string $slug
* @return \Illuminate\Http\Response
*/
public function show($slug)
{
$product = $this->product->findBySlugOrFail($slug);
$productReviews = $this->reviewHelper->getReviews($product)->get();
return $productReviews;
}
/**
* Delete the review of the current product
*
* @return response
*/
public function destroy($id)
{
$this->productReview->delete($id);
session()->flash('success', 'Product Review Successfully Deleted');
return redirect()->back();
}
}

View File

@ -1,126 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Shop;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Webkul\Checkout\Repositories\CartRepository;
use Webkul\Checkout\Repositories\CartItemRepository as CartItem;
use Webkul\API\Http\Controllers\Shop\Presenter as Presenter;
use Auth;
use Cart;
/**
* Cart controller for the APIs of User Cart
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CartController extends Controller
{
protected $customer;
protected $cart;
protected $cartItem;
public function __construct(CartRepository $cart, CartItem $cartItem)
{
$this->cart = $cart;
$this->cartItem = $cartItem;
}
/**
* Function to get the current cart instance for customer or guest
*
* @return Response array && Collection Cart
*/
public function get() {
$cart = Cart::getCart();
if ($cart == null || $cart == 'null') {
return response()->json(['message' => 'empty', 'items' => null]);
}
return response()->json(['message' => 'success', 'items' => $cart]);
}
/**
* Function for guests user to add the product in the cart.
*
* @return Mixed
*/
public function add($id) {
$result = Cart::add($id, request()->all());
if ($result) {
Cart::collectTotals();
return response()->json(['message' => 'successful', 'items' => Cart::getCart()->items]);
} else {
return response()->json(['message' => 'failed', 'items' => Cart::getCart()->items]);
}
}
/**
* Removes the item from the cart if it exists
*
* @param integer $itemId
*/
public function remove($itemId) {
$result = Cart::removeItem($itemId);
Cart::collectTotals();
return response()->json(['message' => $result, 'items' => Cart::getCart()]);
}
/**
* Before checkout starts or full details on the cart
*
* @return response json
*/
public function onePage() {
$cart = Cart::getCart();
if ($cart == null || $cart == 'null') {
return response()->json(['message' => 'empty', 'items' => null]);
}
$presenter = new Presenter();
$summary = $presenter->onePagePresenter($cart);
return response()->json(['message' => 'success', 'items' => $cart->items, 'summary' => $summary]);
}
/**
* Updates the quantity of the items present in the cart.
*
* @return response JSON
*/
public function updateOnePage() {
$request = request()->except('_token');
foreach ($request['qty'] as $id => $quantity) {
if ($quantity <= 0) {
return response()->json(['message' => 'Illegal Quantity', 'status' => 'error']);
}
}
foreach ($request['qty'] as $key => $value) {
$item = $this->cartItem->findOneByField('id', $key);
$data['quantity'] = $value;
$result = Cart::updateItem($item->product_id, $data, $key);
unset($item);
unset($data);
}
Cart::collectTotals();
return response()->json(['message' => 'success', 'items' => Cart::getCart()]);
}
}

View File

@ -1,49 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Shop;
use Webkul\API\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\Event;
use Illuminate\Support\Collection;
use Webkul\Category\Repositories\CategoryRepository as Category;
/**
* Category controller for getting the categories
*
* @author Prashant Singh <prashant.singh852@webkul.com> @prashant-webkul
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class CategoryController extends Controller
{
/**
* The category implementation.
*
* for shop bundle's navigation
* menu
*/
protected $category;
/**
* Category Repository DI.
*
* @param $category Category Instance
* @return void
*/
public function __construct(Category $category)
{
$this->category = $category;
}
public function get() {
$categories = [];
foreach ($this->category->getVisibleCategoryTree() as $category) {
array_push($categories, collect($category));
}
return $categories;
}
}

View File

@ -1,6 +1,6 @@
<?php
namespace Webkul\API\Http\Controllers;
namespace Webkul\API\Http\Controllers\Shop;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;

View File

@ -1,22 +0,0 @@
<?php
namespace Webkul\API\Http\Controllers\Shop;
/**
* Presenter Class for cart and mini cart(if implemented)
*/
class Presenter {
/**
* presenter method will handle the cart and collect all the necessary data to be displayed on the onepage cart
*/
public function onePagePresenter($cart) {
$cartSummary['grand_total'] = $cart->grand_total;
$cartSummary['tax_total'] = $cart->tax_total;
$cartSummary['total_items'] = $cart->items_count;
$cartSummary['total_items_qty'] = $cart->items_qty;
$cartSummary['total_items_qty'] = $cart->items_qty;
return $cartSummary;
}
}

View File

@ -0,0 +1,59 @@
<?php
namespace Webkul\API\Http\Controllers\Shop;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Product\Repositories\ProductRepository;
use Webkul\API\Http\Resources\Catalog\Product as ProductResource;
/**
* Product controller
*
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ProductController extends Controller
{
/**
* ProductRepository object
*
* @var array
*/
protected $productRepository;
/**
* Create a new controller instance.
*
* @param Webkul\Product\Repositories\ProductRepository $productRepository
* @return void
*/
public function __construct(ProductRepository $productRepository)
{
// $this->middleware('auth:api');
$this->productRepository = $productRepository;
}
/**
* Returns a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
return ProductResource::collection($this->productRepository->getAll());
}
/**
* Returns a individual resource.
*
* @return \Illuminate\Http\Response
*/
public function get($id)
{
return new ProductResource(
$this->productRepository->findOrFail($id)
);
}
}

View File

@ -0,0 +1,73 @@
<?php
namespace Webkul\API\Http\Controllers\Shop;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
/**
* Resource Controller
*
* @author Jitendra Singh <jitendra@webkul.com>
* @copyright 2018 Webkul Software Pvt Ltd (http://www.webkul.com)
*/
class ResourceController extends Controller
{
/**
* Contains route related configuration
*
* @var array
*/
protected $_config;
/**
* Repository object
*
* @var array
*/
protected $repository;
/**
* Create a new controller instance.
*
* @return void
*/
public function __construct()
{
// $this->middleware('auth:api');
$this->_config = request('_config');
$this->repository = app($this->_config['repository']);
}
/**
* Returns a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index()
{
$results = $this->repository->scopeQuery(function($query) {
foreach (request()->except(['page', 'limit']) as $input => $value) {
$query = $query->where($input, $value);
}
return $query;
})->paginate(request()->input('limit') ?? 10);
return $this->_config['resource']::collection($results);
}
/**
* Returns a individual resource.
*
* @return \Illuminate\Http\Response
*/
public function get($id)
{
return new $this->_config['resource'](
$this->repository->findOrFail($id)
);
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Webkul\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class Attribute extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'swatch_type' => $this->swatch_type,
'options' => AttributeOption::collection($this->options),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,27 @@
<?php
namespace Webkul\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class AttributeFamily extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'status' => $this->status,
'groups' => AttributeGroup::collection($this->attribute_groups),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Webkul\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class AttributeGroup extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'swatch_type' => $this->swatch_type,
'attributes' => Attribute::collection($this->custom_attributes)
];
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Webkul\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class AttributeOption extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'admin_name' => $this->admin_name,
'label' => $this->label,
'swatch_value' => $this->swatch_value
];
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Webkul\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class Category extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'image_url' => $this->image_url,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,52 @@
<?php
namespace Webkul\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class Product extends JsonResource
{
/**
* Create a new resource instance.
*
* @return void
*/
public function __construct($resource)
{
$this->productPriceHelper = app('Webkul\Product\Helpers\Price');
parent::__construct($resource);
}
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
$product = $this->product ? $this->product : $this;
return [
'id' => $product->id,
'type' => $product->type,
'name' => $this->name,
'price' => $this->price,
'description' => $this->description,
'sku' => $this->sku,
'images' => ProductImage::collection($product->images),
'variants' => Self::collection($this->variants),
'in_stock' => $product->haveSufficientQuantity(1),
$this->mergeWhen($product->type == 'configurable', [
'super_attributes' => Attribute::collection($product->super_attributes),
]),
'special_price' => $this->when(
$this->productPriceHelper->haveSpecialPrice($product),
$this->productPriceHelper->getSpecialPrice($product)
),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,26 @@
<?php
namespace Webkul\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
class ProductImage extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'path' => $this->path,
'url' => $this->url,
'small_image_url' => url('cache/small/' . $this->path),
'medium_image_url' => url('cache/medium/' . $this->path),
'large_image_url' => url('cache/large/' . $this->path)
];
}
}

View File

@ -0,0 +1,31 @@
<?php
namespace Webkul\API\Http\Resources\Catalog;
use Illuminate\Http\Resources\Json\JsonResource;
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
class ProductReview extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'rating' => $this->rating,
'comment' => $this->comment,
'name' => $this->name,
'status' => $this->status,
'product' => new Product($this->product),
'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,41 @@
<?php
namespace Webkul\API\Http\Resources\Core;
use Illuminate\Http\Resources\Json\JsonResource;
use Webkul\API\Http\Resources\Core\Locale as LocaleResource;
use Webkul\API\Http\Resources\Core\Currency as CurrencyResource;
use Webkul\API\Http\Resources\Catalog\Category as CategoryResource;
class Channel extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'description' => $this->description,
'timezone' => $this->timezone,
'theme' => $this->theme,
'home_page_content' => $this->home_page_content,
'footer_content' => $this->footer_content,
'hostname' => $this->hostname,
'logo' => $this->logo,
'logo_url' => $this->logo_url,
'favicon' => $this->favicon,
'favicon_url' => $this->favicon_url,
'default_locale' => $this->when($this->default_locale_id, new LocaleResource($this->default_locale)),
'base_currency' => $this->when($this->default_currency_id, new CurrencyResource($this->default_currency)),
'root_category' => $this->when($this->root_category_id, new CategoryResource($this->root_category)),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Webkul\API\Http\Resources\Core;
use Illuminate\Http\Resources\Json\JsonResource;
class Currency extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Webkul\API\Http\Resources\Core;
use Illuminate\Http\Resources\Json\JsonResource;
class Locale extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Webkul\API\Http\Resources\Core;
use Illuminate\Http\Resources\Json\JsonResource;
class Slider extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'title' => $this->title,
'image_url' => $this->image_url,
'content' => $this->content
];
}
}

View File

@ -0,0 +1,32 @@
<?php
namespace Webkul\API\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class Customer extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'email' => $this->email,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'name' => $this->name,
'gender' => $this->gender,
'date_of_birth' => $this->date_of_birth,
'phone' => $this->phone,
'status' => $this->status,
'group' => $this->when($this->customer_group_id, new CustomerGroup($this->group)),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,30 @@
<?php
namespace Webkul\API\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class CustomerAddress extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'address1' => $this->address1,
'address2' => $this->address2,
'country' => $this->country,
'state' => $this->state,
'city' => $this->city,
'postcode' => $this->postcode,
'phone' => $this->phone,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,24 @@
<?php
namespace Webkul\API\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
class CustomerGroup extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,25 @@
<?php
namespace Webkul\API\Http\Resources\Customer;
use Illuminate\Http\Resources\Json\JsonResource;
use Webkul\API\Http\Resources\Catalog\Product as ProductResource;
class Wishlist extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'product' => new ProductResource($this->product),
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,39 @@
<?php
namespace Webkul\API\Http\Resources\Inventory;
use Illuminate\Http\Resources\Json\JsonResource;
class InventorySource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'code' => $this->code,
'name' => $this->name,
'description' => $this->description,
'contact_name' => $this->contact_name,
'contact_email' => $this->contact_email,
'contact_number' => $this->contact_number,
'contact_fax' => $this->contact_fax,
'country' => $this->country,
'state' => $this->state,
'city' => $this->city,
'street' => $this->street,
'postcode' => $this->postcode,
'priority' => $this->priority,
'latitude' => $this->latitude,
'longitude' => $this->collongitudeongitudeuntry,
'status' => $this->status,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,40 @@
<?php
namespace Webkul\API\Http\Resources\Sales;
use Illuminate\Http\Resources\Json\JsonResource;
class Invoice extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'state' => $this->state,
'email_sent' => $this->email_sent,
'total_qty' => $this->total_qty,
'base_currency_code' => $this->base_currency_code,
'channel_currency_code' => $this->channel_currency_code,
'order_currency_code' => $this->order_currency_code,
'sub_total' => $this->sub_total,
'base_sub_total' => $this->base_sub_total,
'grand_total' => $this->grand_total,
'base_grand_total' => $this->base_grand_total,
'shipping_amount' => $this->shipping_amount,
'base_shipping_amount' => $this->base_shipping_amount,
'tax_amount' => $this->tax_amount,
'base_tax_amount' => $this->base_tax_amount,
'discount_amount' => $this->discount_amount,
'base_discount_amount' => $this->base_discount_amount,
'order_address' => new OrderAddress($this->address),
'transaction_id' => $this->transaction_id,
'items' => InvoiceItem::collection($this->items),
];
}
}

View File

@ -0,0 +1,36 @@
<?php
namespace Webkul\API\Http\Resources\Sales;
use Illuminate\Http\Resources\Json\JsonResource;
class InvoiceItem extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'sku' => $this->sku,
'description' => $this->description,
'qty' => $this->qty,
'price' => $this->price,
'base_price' => $this->base_price,
'total' => $this->total,
'base_total' => $this->base_total,
'tax_amount' => $this->tax_amount,
'base_tax_amount' => $this->base_tax_amount,
'additional' => is_array($this->resource->additional)
? $this->resource->additional
: json_decode($this->resource->additional, true),
'child' => new self($this->child)
];
}
}

View File

@ -0,0 +1,76 @@
<?php
namespace Webkul\API\Http\Resources\Sales;
use Illuminate\Http\Resources\Json\JsonResource;
use Webkul\API\Http\Resources\Core\Channel as ChannelResource;
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
class Order extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'status' => $this->status,
'channel_name' => $this->channel_name,
'is_guest' => $this->is_guest,
'customer_email' => $this->customer_email,
'customer_first_name' => $this->customer_first_name,
'customer_last_name' => $this->customer_last_name,
'shipping_method' => $this->shipping_method,
'shipping_title' => $this->shipping_title,
'shipping_description' => $this->shipping_description,
'coupon_code' => $this->coupon_code,
'is_gift' => $this->is_gift,
'total_item_count' => $this->total_item_count,
'total_qty_ordered' => $this->total_qty_ordered,
'base_currency_code' => $this->base_currency_code,
'channel_currency_code' => $this->channel_currency_code,
'order_currency_code' => $this->order_currency_code,
'grand_total' => $this->grand_total,
'base_grand_total' => $this->base_grand_total,
'grand_total_invoiced' => $this->grand_total_invoiced,
'base_grand_total_invoiced' => $this->base_grand_total_invoiced,
'grand_total_refunded' => $this->grand_total_refunded,
'base_grand_total_refunded' => $this->base_grand_total_refunded,
'sub_total' => $this->sub_total,
'base_sub_total' => $this->base_sub_total,
'sub_total_invoiced' => $this->sub_total_invoiced,
'base_sub_total_invoiced' => $this->base_sub_total_invoiced,
'sub_total_refunded' => $this->sub_total_refunded,
'discount_percent' => $this->discount_percent,
'discount_amount' => $this->discount_amount,
'base_discount_amount' => $this->base_discount_amount,
'discount_invoiced' => $this->discount_invoiced,
'base_discount_invoiced' => $this->base_discount_invoiced,
'discount_refunded' => $this->discount_refunded,
'base_discount_refunded' => $this->base_discount_refunded,
'tax_amount' => $this->tax_amount,
'base_tax_amount' => $this->base_tax_amount,
'tax_amount_invoiced' => $this->tax_amount_invoiced,
'base_tax_amount_invoiced' => $this->base_tax_amount_invoiced,
'tax_amount_refunded' => $this->tax_amount_refunded,
'base_tax_amount_refunded' => $this->base_tax_amount_refunded,
'shipping_amount' => $this->shipping_amount,
'base_shipping_amount' => $this->base_shipping_amount,
'shipping_invoiced' => $this->shipping_invoiced,
'base_shipping_invoiced' => $this->base_shipping_invoiced,
'shipping_refunded' => $this->shipping_refunded,
'base_shipping_refunded' => $this->base_shipping_refunded,
'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)),
'channel' => $this->when($this->channel_id, new ChannelResource($this->channel)),
'updated_at' => $this->updated_at,
'items' => OrderItem::collection($this->items),
'invoices' => Invoice::collection($this->invoices),
'shipments' => Shipment::collection($this->shipments),
'created_at' => $this->created_at
];
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Webkul\API\Http\Resources\Sales;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderAddress extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'email' => $this->email,
'first_name' => $this->first_name,
'last_name' => $this->last_name,
'address1' => $this->address1,
'address2' => $this->address2,
'country' => $this->country,
'state' => $this->state,
'city' => $this->city,
'postcode' => $this->postcode,
'phone' => $this->phone,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
];
}
}

View File

@ -0,0 +1,57 @@
<?php
namespace Webkul\API\Http\Resources\Sales;
use Illuminate\Http\Resources\Json\JsonResource;
class OrderItem extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'sku' => $this->sku,
'type' => $this->type,
'name' => $this->name,
'coupon_code' => $this->coupon_code,
'weight' => $this->weight,
'total_weight' => $this->total_weight,
'qty_ordered' => $this->qty_ordered,
'qty_canceled' => $this->qty_canceled,
'qty_shipped' => $this->qty_shipped,
'qty_refunded' => $this->qty_refunded,
'price' => $this->price,
'base_price' => $this->base_price,
'total' => $this->total,
'base_total' => $this->base_total,
'total_invoiced' => $this->total_invoiced,
'base_total_invoiced' => $this->base_total_invoiced,
'amount_refunded' => $this->amount_refunded,
'base_amount_refunded' => $this->base_amount_refunded,
'discount_percent' => $this->discount_percent,
'discount_amount' => $this->discount_amount,
'base_discount_amount' => $this->base_discount_amount,
'discount_invoiced' => $this->discount_invoiced,
'base_discount_invoiced' => $this->base_discount_invoiced,
'discount_refunded' => $this->discount_refunded,
'base_discount_refunded' => $this->base_discount_refunded,
'tax_percent' => $this->tax_percent,
'tax_amount' => $this->tax_amount,
'base_tax_amount' => $this->base_tax_amount,
'tax_amount_invoiced' => $this->tax_amount_invoiced,
'base_tax_amount_invoiced' => $this->base_tax_amount_invoiced,
'tax_amount_refunded' => $this->tax_amount_refunded,
'base_tax_amount_refunded' => $this->base_tax_amount_refunded,
'additional' => is_array($this->resource->additional)
? $this->resource->additional
: json_decode($this->resource->additional, true),
'child' => new self($this->child)
];
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Webkul\API\Http\Resources\Sales;
use Illuminate\Http\Resources\Json\JsonResource;
use Webkul\API\Http\Resources\Customer\Customer as CustomerResource;
use Webkul\API\Http\Resources\Inventory\InventorySource as InventorySourceResource;
class Shipment extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'status' => $this->status,
'total_qty' => $this->total_qty,
'total_weight' => $this->total_weight,
'carrier_code' => $this->carrier_code,
'carrier_title' => $this->carrier_title,
'track_number' => $this->track_number,
'email_sent' => $this->email_sent,
'customer' => $this->when($this->customer_id, new CustomerResource($this->customer)),
'inventory_source' => $this->when($this->inventory_source_id, new InventorySourceResource($this->inventory_source)),
'items' => ShipmentItem::collection($this->items),
];
}
}

View File

@ -0,0 +1,33 @@
<?php
namespace Webkul\API\Http\Resources\Sales;
use Illuminate\Http\Resources\Json\JsonResource;
class ShipmentItem extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request
* @return array
*/
public function toArray($request)
{
return [
'id' => $this->id,
'name' => $this->name,
'description' => $this->description,
'sku' => $this->sku,
'qty' => $this->qty,
'weight' => $this->weight,
'price' => $this->price,
'base_price' => $this->base_price,
'total' => $this->total,
'base_total' => $this->base_total,
'additional' => is_array($this->resource->additional)
? $this->resource->additional
: json_decode($this->resource->additional, true)
];
}
}

View File

@ -1,76 +0,0 @@
<?php
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Customer', 'prefix' => 'api/customer'], function ($router) {
//customer registration API
Route::post('/register', 'RegistrationController@create');
//auth route for customer
Route::post('login', 'AuthController@create');
//auth route for customer
Route::post('logout', 'AuthController@destroy');
//get customer profile
Route::get('get/profile', 'CustomerController@getProfile');
Route::put('update/profile/{id}', 'CustomerController@updateProfile');
//wishlist
//get wishlist
Route::get('get/wishlist', 'WishlistController@getWishlist');
//add the item in the wishlist
Route::get('add/wishlist/{id}', 'WishlistController@add');
//delete the item from the wishlist
Route::get('delete/wishlist/{id}', 'WishlistController@delete');
//Move the item from the wishlist to cart
// Route::get('delete/wishlist/{id}', 'WishlistController@delete');
//address
Route::get('get/address', 'AddressController@get');
Route::get('get/default/address', 'AddressController@getDefault');
Route::post('create/address', 'AddressController@create');
Route::put('make/default/address/{id}', 'AddressController@makeDefault');
Route::delete('delete/address/{id}', 'AddressController@delete');
//cart -> not to be used
//active + inactive instances of cart for the current logged in user
Route::get('get/all', 'CustomerController@getAllCart');
//active instances of cart for the current logged in user
Route::get('get/active', 'CustomerController@getActiveCart');
});
//all the cart related API for customer and guests
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'prefix' => 'api/cart'], function ($router) {
//cart
Route::get('get', 'CartController@get');
//add item in the cart
Route::post('add/{id}', 'CartController@add');
//remove item to the cart
Route::get('remove/{id}', 'CartController@remove');
//get cart and all item for cart checkout
Route::get('/onepage', 'CartController@onePage');
//update OnePage
Route::put('/update/onepage', 'CartController@updateOnePage');
});
//all the product related API to be used for store front
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Product', 'prefix' => 'api/product'], function ($router) {
//product
//to get all products
Route::get('get/all', 'ProductController@getAll');
//to fetch the new products
Route::get('get/new', 'ProductController@getNew');
//to fetch the featured product
Route::get('get/featured', 'ProductController@getFeatured');
//to get the product by its slug
Route::get('get/{slug}', 'ProductController@getBySlug');
//product reviews get and create
//to get the reviews of the product
Route::get('review/{slug}', 'ReviewController@show');
//to store the review for a product
Route::post('review/{slug}', 'ReviewController@create');
});
//all the shop related API to be used for store front
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop', 'prefix' => 'api/shop'], function ($router) {
Route::get('get/category', 'CategoryController@get');
});

View File

@ -0,0 +1,175 @@
<?php
Route::group(['prefix' => 'api'], function ($router) {
Route::group(['namespace' => 'Webkul\API\Http\Controllers\Shop'], function ($router) {
//Category routes
Route::get('categories', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Category\Repositories\CategoryRepository',
'resource' => 'Webkul\API\Http\Resources\Catalog\Category'
]);
Route::get('categories/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Category\Repositories\CategoryRepository',
'resource' => 'Webkul\API\Http\Resources\Catalog\Category'
]);
//Attribute routes
Route::get('attributes', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Attribute\Repositories\AttributeRepository',
'resource' => 'Webkul\API\Http\Resources\Catalog\Attribute'
]);
Route::get('attributes/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Attribute\Repositories\AttributeRepository',
'resource' => 'Webkul\API\Http\Resources\Catalog\Attribute'
]);
//AttributeFamily routes
Route::get('families', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Attribute\Repositories\AttributeFamilyRepository',
'resource' => 'Webkul\API\Http\Resources\Catalog\AttributeFamily'
]);
Route::get('families/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Attribute\Repositories\AttributeFamilyRepository',
'resource' => 'Webkul\API\Http\Resources\Catalog\AttributeFamily'
]);
//Product routes
Route::get('products', 'ProductController@index');
Route::get('products/{id}', 'ProductController@get');
//Product Review routes
Route::get('reviews', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Product\Repositories\ProductReviewRepository',
'resource' => 'Webkul\API\Http\Resources\Catalog\ProductReview'
]);
Route::get('reviews/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Product\Repositories\ProductReviewRepository',
'resource' => 'Webkul\API\Http\Resources\Catalog\ProductReview'
]);
//Channel routes
Route::get('channels', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Core\Repositories\ChannelRepository',
'resource' => 'Webkul\API\Http\Resources\Core\Channel'
]);
Route::get('channels/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Core\Repositories\ChannelRepository',
'resource' => 'Webkul\API\Http\Resources\Core\Channel'
]);
//Locale routes
Route::get('locales', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Core\Repositories\LocaleRepository',
'resource' => 'Webkul\API\Http\Resources\Core\Locale'
]);
Route::get('locales/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Core\Repositories\LocaleRepository',
'resource' => 'Webkul\API\Http\Resources\Core\Locale'
]);
//Slider routes
Route::get('sliders', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Core\Repositories\SliderRepository',
'resource' => 'Webkul\API\Http\Resources\Core\Slider'
]);
Route::get('sliders/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Core\Repositories\SliderRepository',
'resource' => 'Webkul\API\Http\Resources\Core\Slider'
]);
//Currency routes
Route::get('currencies', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Core\Repositories\CurrencyRepository',
'resource' => 'Webkul\API\Http\Resources\Core\Currency'
]);
Route::get('currencies/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Core\Repositories\CurrencyRepository',
'resource' => 'Webkul\API\Http\Resources\Core\Currency'
]);
//Customer routes
Route::get('customers', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Customer\Repositories\CustomerRepository',
'resource' => 'Webkul\API\Http\Resources\Customer\Customer'
]);
Route::get('customers/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Customer\Repositories\CustomerRepository',
'resource' => 'Webkul\API\Http\Resources\Customer\Customer'
]);
//Customer Address routes
Route::get('addresses', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Customer\Repositories\CustomerAddressRepository',
'resource' => 'Webkul\API\Http\Resources\Customer\CustomerAddress'
]);
Route::get('addresses/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Customer\Repositories\CustomerAddressRepository',
'resource' => 'Webkul\API\Http\Resources\Customer\CustomerAddress'
]);
//Order routes
Route::get('orders', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Sales\Repositories\OrderRepository',
'resource' => 'Webkul\API\Http\Resources\Sales\Order'
]);
Route::get('orders/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Sales\Repositories\OrderRepository',
'resource' => 'Webkul\API\Http\Resources\Sales\Order'
]);
//Invoice routes
Route::get('invoices', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Sales\Repositories\InvoiceRepository',
'resource' => 'Webkul\API\Http\Resources\Sales\Invoice'
]);
Route::get('invoices/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Sales\Repositories\InvoiceRepository',
'resource' => 'Webkul\API\Http\Resources\Sales\Invoice'
]);
//Invoice routes
Route::get('shipments', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Sales\Repositories\ShipmentRepository',
'resource' => 'Webkul\API\Http\Resources\Sales\Shipment'
]);
Route::get('shipments/{id}', 'ResourceController@get')->defaults('_config', [
'repository' => 'Webkul\Sales\Repositories\ShipmentRepository',
'resource' => 'Webkul\API\Http\Resources\Sales\Shipment'
]);
//Wishlist routes
Route::get('wishlist', 'ResourceController@index')->defaults('_config', [
'repository' => 'Webkul\Customer\Repositories\WishlistRepository',
'resource' => 'Webkul\API\Http\Resources\Customer\Wishlist'
]);
});
});

View File

@ -13,9 +13,7 @@ class APIServiceProvider extends ServiceProvider
*/
public function boot()
{
$this->loadRoutesFrom(__DIR__.'/../Http/api.php');
$this->loadMigrationsFrom(__DIR__ . '/../Database/Migrations');
$this->loadRoutesFrom(__DIR__.'/../Http/routes.php');
}
/**
@ -25,20 +23,5 @@ class APIServiceProvider extends ServiceProvider
*/
public function register()
{
// $app['Dingo\Api\Auth\Auth']->extend('oauth', function ($app) {
// return new Dingo\Api\Auth\Provider\JWT($app['Tymon\JWTAuth\JWTAuth']);
// });
// $app['Dingo\Api\Http\RateLimit\Handler']->extend(function ($app) {
// return new Dingo\Api\Http\RateLimit\Throttle\Authenticated;
// });
// $app['Dingo\Api\Transformer\Factory']->setAdapter(function ($app) {
// $fractal = new League\Fractal\Manager;
// $fractal->setSerializer(new League\Fractal\Serializer\JsonApiSerializer);
// return new Dingo\Api\Transformer\Adapter\Fractal($fractal);
// });
}
}

View File

@ -12,6 +12,12 @@ use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
class Handler extends ExceptionHandler
{
protected $jsonErrorMessages = [
404 => 'Resource not found',
403 => '403 forbidden Error',
401 => 'Unauthenticated',
500 => '500 Internal Server Error',
];
/**
* Render an exception into an HTTP response.
@ -25,8 +31,8 @@ class Handler extends ExceptionHandler
$path = $this->isAdminUri() ? 'admin' : 'shop';
if ($exception instanceof HttpException) {
$statusCode = $exception->getStatusCode();
$statusCode = in_array($statusCode, [401, 403, 404, 503]) ? $statusCode : 500;
$statusCode = in_array($exception->getStatusCode(), [401, 403, 404, 503]) ? $exception->getStatusCode() : 500;
return $this->response($path, $statusCode);
} else if ($exception instanceof ModelNotFoundException) {
return $this->response($path, 404);
@ -37,6 +43,22 @@ class Handler extends ExceptionHandler
return parent::render($request, $exception);
}
/**
* Convert an authentication exception into a response.
*
* @param \Illuminate\Http\Request $request
* @param \Illuminate\Auth\AuthenticationException $exception
* @return \Illuminate\Http\Response
*/
protected function unauthenticated($request, AuthenticationException $exception)
{
if ($request->expectsJson()) {
return response()->json(['error' => $this->jsonErrorMessages[401]], 401);
}
return redirect()->guest(route('auth.login'));
}
private function isAdminUri()
{
return strpos($_SERVER['REQUEST_URI'], 'admin') !== false ? true : false;
@ -44,7 +66,14 @@ class Handler extends ExceptionHandler
private function response($path, $statusCode)
{
if (request()->expectsJson()) {
return response()->json([
'error' => isset($this->jsonErrorMessages[$statusCode])
? $this->jsonErrorMessages[$statusCode]
: 'Something went wrong, please try again later.'
], $statusCode);
}
return response()->view("{$path}::errors.{$statusCode}", [], $statusCode);
}
}

View File

@ -228,6 +228,11 @@ Route::group(['middleware' => ['web']], function () {
'redirect' => 'admin.catalog.products.index'
])->name('admin.catalog.products.massupdate');
//product search for linked products
Route::get('products/search', 'Webkul\Product\Http\Controllers\ProductController@productLinkSearch')->defaults('_config', [
'view' => 'admin::catalog.products.edit'
])->name('admin.catalog.products.productlinksearch');
// Catalog Category Routes
Route::get('/categories', 'Webkul\Category\Http\Controllers\CategoryController@index')->defaults('_config', [
'view' => 'admin::catalog.categories.index'

View File

@ -1,9 +1,11 @@
window.jQuery = window.$ = $ = require("jquery");
window.Vue = require("vue");
window.VeeValidate = require("vee-validate");
window.axios = require("axios");
require("./bootstrap");
Vue.use(VeeValidate);
Vue.prototype.$http = axios
window.eventBus = new Vue();

View File

@ -380,7 +380,9 @@ return [
'cross-selling' => 'Cross Selling',
'up-selling' => 'Up Selling',
'related-products' => 'Related Products',
'product-search-hint' => 'Start typing product name'
'product-search-hint' => 'Start typing product name',
'no-result-found' => 'Products not found with same name.',
'searching' => 'Searching ...'
],
'attributes' => [
@ -823,7 +825,28 @@ return [
'settings' => 'Settings',
'address' => 'Address',
'address' => 'Address',
'street-lines' => 'Lines in a Street Address'
'street-lines' => 'Lines in a Street Address',
'sales' => 'Sales',
'shipping-methods' => 'Shipping Methods',
'free-shipping' => 'Free Shipping',
'flate-rate-shipping' => 'Flat Rate Shipping',
'shipping' => 'Shipping',
'origin' => 'Origin',
'country' => 'Country',
'state' => 'State',
'zip' => 'Zip',
'city' => 'City',
'street-address' => 'Street Address',
'title' => 'Title',
'description' => 'Description',
'rate' => 'Rate',
'status' => 'Status',
'type' => 'Type',
'payment-methods' => 'Payment Methods',
'cash-on-delivery' => 'Cash On Delivery',
'money-transfer' => 'Money Transfer',
'paypal-standard' => 'Paypal Standard',
'business-account' => 'Business Account'
]
]
];

View File

@ -1,287 +1,167 @@
<accordian :title="'{{ __('admin::app.catalog.products.product-link') }}'" :active="true">
<div slot="body">
<up-selling></up-selling>
<cross-selling></cross-selling>
<related-product></related-product>
<linked-products></linked-products>
</div>
</accordian>
@push('scripts')
<script type="text/x-template" id="up-selling-template">
<script type="text/x-template" id="linked-products-template">
<div>
<div class="control-group">
<label for="up-selling">{{ __('admin::app.catalog.products.up-selling') }}</label>
<input type="text" class="control" autocomplete="off" v-model="search_term" placeholder="{{ __('admin::app.catalog.products.product-search-hint') }}">
<div class="control-group" v-for='(key) in linkedProducts'>
<label for="up-selling" v-if="(key == 'up_sells')">
{{ __('admin::app.catalog.products.up-selling') }}
</label>
<label for="cross_sells" v-if="(key == 'cross_sells')">
{{ __('admin::app.catalog.products.cross-selling') }}
</label>
<label for="related_products" v-if="(key == 'related_products')">
{{ __('admin::app.catalog.products.related-products') }}
</label>
<input type="text" class="control" autocomplete="off" v-model="search_term[key]" placeholder="{{ __('admin::app.catalog.products.product-search-hint') }}" v-on:keyup="search(key)">
<div class="linked-product-search-result">
<ul>
<li v-for='(product, index) in products'@click="addProduct(product)">
<li v-for='(product, index) in products[key]' v-if='products[key].length' @click="addProduct(product, key)">
@{{ product.name }}
</li>
<li v-if='!products[key].length && search_term[key].length && !is_searching[key]'>
{{ __('admin::app.catalog.products.no-result-found') }}
</li>
<li v-if="is_searching[key] && search_term[key].length">
{{ __('admin::app.catalog.products.searching') }}
</li>
</ul>
</div>
<input type="hidden" name="up_sell[]" v-for='(product, index) in this.addedProduct' :value="product.id"/>
<input type="hidden" name="up_sell[]" v-for='(product, index) in addedProducts.up_sells' v-if="(key == 'up_sells') && addedProducts.up_sells.length" :value="product.id"/>
<span class="filter-tag" v-if="this.addedProduct.length" style="text-transform: capitalize; margin-top: 10px; margin-right: 0px; justify-content: flex-start">
<span class="wrapper" style="margin-left: 0px; margin-right: 10px;" v-for='(product, index) in this.addedProduct'>
@{{ product.name }}
<span class="icon cross-icon" @click="removeProduct(product)"></span>
<input type="hidden" name="cross_sell[]" v-for='(product, index) in addedProducts.cross_sells' v-if="(key == 'cross_sells') && addedProducts.cross_sells.length" :value="product.id"/>
<input type="hidden" name="related_products[]" v-for='(product, index) in addedProducts.related_products' v-if="(key == 'related_products') && addedProducts.related_products.length" :value="product.id"/>
<span class="filter-tag" style="text-transform: capitalize; margin-top: 10px; margin-right: 0px; justify-content: flex-start" v-if="addedProducts[key].length">
<span class="wrapper" style="margin-left: 0px; margin-right: 10px;" v-for='(product, index) in addedProducts[key]'>
@{{ product.name }}
<span class="icon cross-icon" @click="removeProduct(product, key)"></span>
</span>
</span>
</div>
</div>
</script>
<script>
Vue.component('up-selling', {
Vue.component('linked-products', {
template: '#up-selling-template',
template: '#linked-products-template',
data: () => ({
allProduct: @json($allProducts),
products: {
'cross_sells': [],
'up_sells': [],
'related_products': []
},
search_term: '',
search_term: {
'cross_sells': '',
'up_sells': '',
'related_products': ''
},
addedProduct: [],
addedProducts: {
'cross_sells': [],
'up_sells': [],
'related_products': []
},
upSellingProduct: @json($product->up_sells()->get()),
is_searching: {
'cross_sells': false,
'up_sells': false,
'related_products': false
},
productId: {{ $product->id }},
linkedProducts: ['up_sells', 'cross_sells', 'related_products'],
upSellingProducts: @json($product->up_sells()->get()),
crossSellingProducts: @json($product->cross_sells()->get()),
relatedProducts: @json($product->related_products()->get()),
}),
created () {
if (this.upSellingProduct.length >= 1) {
for (var index in this.upSellingProduct) {
this.addedProduct.push(this.upSellingProduct[index]);
for (var index1 in this.allProduct) {
if (this.allProduct[index1].id == this.upSellingProduct[index].id) {
this.allProduct.splice(index1, 1);
}
}
if (this.upSellingProducts.length >= 1) {
for (var index in this.upSellingProducts) {
this.addedProducts.up_sells.push(this.upSellingProducts[index]);
}
}
},
computed: {
products () {
if (this.search_term.length >= 1) {
return this.allProduct.filter(product => {
return product.name.toLowerCase().includes(this.search_term.toLowerCase())
})
if (this.crossSellingProducts.length >= 1) {
for (var index in this.crossSellingProducts) {
this.addedProducts.cross_sells.push(this.crossSellingProducts[index]);
}
}
if (this.relatedProducts.length >= 1) {
for (var index in this.relatedProducts) {
this.addedProducts.related_products.push(this.relatedProducts[index]);
}
}
},
methods: {
addProduct(product) {
this.addedProduct.push(product);
this.search_term = '';
addProduct (product, key) {
this.addedProducts[key].push(product);
this.search_term[key] = '';
this.products[key] = []
},
for (var index in this.allProduct) {
if (this.allProduct[index].id == product.id) {
this.allProduct.splice(index, 1);
removeProduct (product, key) {
for (var index in this.addedProducts[key]) {
if (this.addedProducts[key][index].id == product.id ) {
this.addedProducts[key].splice(index, 1);
}
}
},
removeProduct(product) {
for (var index in this.addedProduct) {
if (this.addedProduct[index].id == product.id ) {
this.allProduct.push(product);
this.addedProduct.splice(index, 1);
}
}
},
}
});
search (key) {
this_this = this;
</script>
this.is_searching[key] = true;
<script type="text/x-template" id="cross-selling-template">
<div>
<div class="control-group">
<label for="up-selling">{{ __('admin::app.catalog.products.cross-selling') }}</label>
<input type="text" class="control" autocomplete="off" v-model="search_term" placeholder="{{ __('admin::app.catalog.products.product-search-hint') }}">
if (this.search_term[key].length >= 1) {
this.$http.get ("{{ route('admin.catalog.products.productlinksearch') }}", {params: {query: this.search_term[key]}})
.then (function(response) {
<div class="linked-product-search-result">
<ul>
<li v-for='(product, index) in products'@click="addProduct(product)">
@{{ product.name }}
</li>
</ul>
</div>
for (var index in response.data) {
if (response.data[index].id == this_this.productId) {
response.data.splice(index, 1);
}
}
<input type="hidden" name="cross_sell[]" v-for='(product, index) in this.addedProduct' :value="product.id"/>
this_this.products[key] = response.data;
<span class="filter-tag" v-if="this.addedProduct.length" style="text-transform: capitalize; margin-top: 10px; margin-right: 0px; justify-content: flex-start">
<span class="wrapper" style="margin-left: 0px; margin-right: 10px;" v-for='(product, index) in this.addedProduct'>
@{{ product.name }}
<span class="icon cross-icon" @click="removeProduct(product)"></span>
</span>
</span>
</div>
</div>
</script>
this_this.is_searching[key] = false;
})
<script>
Vue.component('cross-selling', {
template: '#cross-selling-template',
data: () => ({
allProduct: @json($allProducts),
search_term: '',
addedProduct: [],
crossSellingProduct: @json($product->cross_sells()->get()),
}),
created () {
if (this.crossSellingProduct.length >= 1) {
for (var index in this.crossSellingProduct) {
this.addedProduct.push(this.crossSellingProduct[index]);
for (var index1 in this.allProduct) {
if (this.allProduct[index1].id == this.crossSellingProduct[index].id) {
this.allProduct.splice(index1, 1);
}
}
.catch (function (error) {
this_this.is_searching[key] = false;
})
} else {
this_this.products[key] = [];
this_this.is_searching[key] = false;
}
}
},
computed: {
products () {
if (this.search_term.length >= 1) {
return this.allProduct.filter(product => {
return product.name.toLowerCase().includes(this.search_term.toLowerCase())
})
}
}
},
methods: {
addProduct(product) {
this.addedProduct.push(product);
this.search_term = '';
for (var index in this.allProduct) {
if (this.allProduct[index].id == product.id) {
this.allProduct.splice(index, 1);
}
}
},
removeProduct(product) {
for (var index in this.addedProduct) {
if (this.addedProduct[index].id == product.id ) {
this.allProduct.push(product);
this.addedProduct.splice(index, 1);
}
}
},
}
});
</script>
<script type="text/x-template" id="related-product-template">
<div>
<div class="control-group">
<label for="up-selling">{{ __('admin::app.catalog.products.related-products') }}</label>
<input type="text" class="control" autocomplete="off" v-model="search_term" placeholder="{{ __('admin::app.catalog.products.product-search-hint') }}">
<div class="linked-product-search-result">
<ul>
<li v-for='(product, index) in products'@click="addProduct(product)">
@{{ product.name }}
</li>
</ul>
</div>
<input type="hidden" name="related_products[]" v-for='(product, index) in this.addedProduct' :value="product.id"/>
<span class="filter-tag" v-if="this.addedProduct.length" style="text-transform: capitalize; margin-top: 10px; margin-right: 0px; justify-content: flex-start">
<span class="wrapper" style="margin-left: 0px; margin-right: 10px;" v-for='(product, index) in this.addedProduct'>
@{{ product.name }}
<span class="icon cross-icon" @click="removeProduct(product)"></span>
</span>
</span>
</div>
</div>
</script>
<script>
Vue.component('related-product', {
template: '#related-product-template',
data: () => ({
allProduct: @json($allProducts),
search_term: '',
addedProduct: [],
relatedProduct: @json($product->related_products()->get()),
}),
created () {
if (this.relatedProduct.length >= 1) {
for (var index in this.relatedProduct) {
this.addedProduct.push(this.relatedProduct[index]);
for (var index1 in this.allProduct) {
if (this.allProduct[index1].id == this.relatedProduct[index].id) {
this.allProduct.splice(index1, 1);
}
}
}
}
},
computed: {
products () {
if (this.search_term.length >= 1) {
return this.allProduct.filter(product => {
return product.name.toLowerCase().includes(this.search_term.toLowerCase())
})
}
}
},
methods: {
addProduct(product) {
this.addedProduct.push(product);
this.search_term = '';
for (var index in this.allProduct) {
if (this.allProduct[index].id == product.id) {
this.allProduct.splice(index, 1);
}
}
},
removeProduct(product) {
for (var index in this.addedProduct) {
if (this.addedProduct[index].id == product.id ) {
this.allProduct.push(product);
this.addedProduct.splice(index, 1);
}
}
},
}
});

View File

@ -78,7 +78,7 @@
<label for="customerGroup" >{{ __('admin::app.customers.customers.customer_group') }}</label>
@if (! is_null($customer->customer_group_id))
<?php $selectedCustomerOption = $customer->customerGroup->id ?>
<?php $selectedCustomerOption = $customer->group->id ?>
@else
<?php $selectedCustomerOption = '' ?>
@endif

View File

@ -119,7 +119,7 @@
</span>
<span class="value">
{{ $order->customer->customerGroup['name'] }}
{{ $order->customer->group['name'] }}
</span>
</div>
@endif

View File

@ -30,9 +30,9 @@ class Customer extends Authenticatable implements CustomerContract
/**
* Get the customer group that owns the customer.
*/
public function customerGroup()
public function group()
{
return $this->belongsTo(CustomerGroupProxy::modelClass());
return $this->belongsTo(CustomerGroupProxy::modelClass(), 'customer_group_id');
}
/**

View File

@ -3,33 +3,33 @@
return [
[
'key' => 'sales',
'name' => 'Sales',
'name' => 'admin::app.admin.system.sales',
'sort' => 1
], [
'key' => 'sales.paymentmethods',
'name' => 'Payment Methods',
'name' => 'admin::app.admin.system.payment-methods',
'sort' => 2,
], [
'key' => 'sales.paymentmethods.cashondelivery',
'name' => 'Cash On Delivery',
'name' => 'admin::app.admin.system.cash-on-delivery',
'sort' => 1,
'fields' => [
[
'name' => 'title',
'title' => 'Title',
'title' => 'admin::app.admin.system.title',
'type' => 'text',
'validation' => 'required',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'title' => 'admin::app.admin.system.description',
'type' => 'textarea',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'active',
'title' => 'Status',
'title' => 'admin::app.admin.system.status',
'type' => 'select',
'options' => [
[
@ -45,25 +45,25 @@ return [
]
], [
'key' => 'sales.paymentmethods.moneytransfer',
'name' => 'Money Transfer',
'name' => 'admin::app.admin.system.money-transfer',
'sort' => 2,
'fields' => [
[
'name' => 'title',
'title' => 'Title',
'title' => 'admin::app.admin.system.title',
'type' => 'text',
'validation' => 'required',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'title' => 'admin::app.admin.system.description',
'type' => 'textarea',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'active',
'title' => 'Status',
'title' => 'admin::app.admin.system.status',
'type' => 'select',
'options' => [
[
@ -79,31 +79,31 @@ return [
]
], [
'key' => 'sales.paymentmethods.paypal_standard',
'name' => 'Paypal Standard',
'name' => 'admin::app.admin.system.paypal-standard',
'sort' => 3,
'fields' => [
[
'name' => 'title',
'title' => 'Title',
'title' => 'admin::app.admin.system.title',
'type' => 'text',
'validation' => 'required',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'title' => 'admin::app.admin.system.description',
'type' => 'textarea',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'business_account',
'title' => 'Business Account',
'title' => 'admin::app.admin.system.business-account',
'type' => 'select',
'type' => 'text',
'validation' => 'required'
], [
'name' => 'active',
'title' => 'Status',
'title' => 'admin::app.admin.system.status',
'type' => 'select',
'options' => [
[

View File

@ -268,4 +268,28 @@ class ProductController extends Controller
return redirect()->route('admin.catalog.products.index');
}
/**
* Result of search product.
*
* @return \Illuminate\Http\Response
*/
public function productLinkSearch()
{
if (request()->ajax()) {
$results = [];
foreach ($this->product->searchProductByAttribute(request()->input('query')) as $row) {
$results[] = [
'id' => $row->product_id,
'sku' => $row->sku,
'name' => $row->name,
];
}
return response()->json($results);
} else {
return view($this->_config['view']);
}
}
}

View File

@ -196,14 +196,23 @@ class ProductRepository extends Repository
if (isset($data['up_sell'])) {
$product->up_sells()->sync($data['up_sell']);
} else {
$data['up_sell'] = [];
$product->up_sells()->sync($data['up_sell']);
}
if (isset($data['cross_sell'])) {
$product->cross_sells()->sync($data['cross_sell']);
} else {
$data['cross_sell'] = [];
$product->cross_sells()->sync($data['cross_sell']);
}
if (isset($data['related_products'])) {
$product->related_products()->sync($data['related_products']);
} else {
$data['related_products'] = [];
$product->related_products()->sync($data['related_products']);
}
$previousVariantIds = $product->variants->pluck('id');

View File

@ -3,34 +3,34 @@
return [
[
'key' => 'sales',
'name' => 'Sales',
'name' => 'admin::app.admin.system.sales',
'sort' => 1
], [
'key' => 'sales.carriers',
'name' => 'Shipping Methods',
'name' => 'admin::app.admin.system.shipping-methods',
'sort' => 1,
], [
'key' => 'sales.carriers.free',
'name' => 'Free Shipping',
'name' => 'admin::app.admin.system.free-shipping',
'sort' => 1,
'fields' => [
[
'name' => 'title',
'title' => 'Title',
'title' => 'admin::app.admin.system.title',
'type' => 'text',
'validation' => 'required',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'title' => 'admin::app.admin.system.description',
'type' => 'textarea',
'channel_based' => false,
'locale_based' => true
], [
'name' => 'active',
'title' => 'Status',
'type' => 'multiselect',
'title' => 'admin::app.admin.system.status',
'type' => 'select',
'options' => [
[
'title' => 'Active',
@ -45,31 +45,31 @@ return [
]
], [
'key' => 'sales.carriers.flatrate',
'name' => 'Flat Rate Shipping',
'name' => 'admin::app.admin.system.flate-rate-shipping',
'sort' => 2,
'fields' => [
[
'name' => 'title',
'title' => 'Title',
'title' => 'admin::app.admin.system.title',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => true
], [
'name' => 'description',
'title' => 'Description',
'title' => 'admin::app.admin.system.description',
'type' => 'textarea',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'default_rate',
'title' => 'Rate',
'title' => 'admin::app.admin.system.rate',
'type' => 'text',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'type',
'title' => 'Type',
'title' => 'admin::app.admin.system.type',
'type' => 'select',
'options' => [
[
@ -83,7 +83,7 @@ return [
'validation' => 'required'
], [
'name' => 'active',
'title' => 'Status',
'title' => 'admin::app.admin.system.status',
'type' => 'select',
'options' => [
[
@ -99,44 +99,44 @@ return [
]
], [
'key' => 'sales.shipping',
'name' => 'Shipping',
'name' => 'admin::app.admin.system.shipping',
'sort' => 0
], [
'key' => 'sales.shipping.origin',
'name' => 'Origin',
'name' => 'admin::app.admin.system.origin',
'sort' => 0,
'fields' => [
[
'name' => 'country',
'title' => 'Country',
'title' => 'admin::app.admin.system.country',
'type' => 'country',
'validation' => 'required',
'channel_based' => true,
'locale_based' => true
], [
'name' => 'state',
'title' => 'State',
'title' => 'admin::app.admin.system.state',
'type' => 'state',
'validation' => 'required',
'channel_based' => true,
'locale_based' => true
], [
'name' => 'address1',
'title' => 'Street Address',
'title' => 'admin::app.admin.system.street-address',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'zipcode',
'title' => 'Zip',
'title' => 'admin::app.admin.system.zip',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,
'locale_based' => false
], [
'name' => 'city',
'title' => 'City',
'title' => 'admin::app.admin.system.city',
'type' => 'text',
'validation' => 'required',
'channel_based' => true,

View File

@ -9,7 +9,6 @@
@foreach ($products as $product)
@if ($product->cross_sells()->count())
<div class="attached-products-wrapper mt-50">
<div class="title">
@ -19,7 +18,7 @@
<div class="product-grid-4">
@foreach ($product->cross_sells()->paginate(4) as $cross_sell_product)
@foreach ($product->cross_sells()->paginate(1) as $cross_sell_product)
@include ('shop::products.list.card', ['product' => $cross_sell_product])
@ -28,6 +27,7 @@
</div>
</div>
@endif
@endforeach