Wishlist Move To Cart For Simple Products Done

This commit is contained in:
prashant-webkul 2018-10-15 20:18:58 +05:30
parent 2f427d1550
commit 3a17aacd90
14 changed files with 89 additions and 126 deletions

View File

@ -107,8 +107,6 @@ class Cart {
{
$product = $this->product->findOneByField('id', $productId);
// dd($product);
//Check if the product's information is proper or not.
if(!isset($data['product']) || !isset($data['quantity'])) {
session()->flash('error', trans('shop::app.checkout.cart.integrity.missing_fields'));
@ -961,4 +959,24 @@ class Cart {
return $finalData;
}
/**
* Move to Cart
*
* Move a wishlist item to cart
*/
public function moveToCart($productId) {
$data = [
'product' => $productId,
'quantity' => 1,
];
$result = $this->add($productId, $data);
if($result instanceof Collection || $result == true) {
return true;
} else {
return false;
}
}
}

View File

@ -5,7 +5,9 @@ namespace Webkul\Customer\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Webkul\Customer\Repositories\CustomerRepository;
use Webkul\Product\Repositories\ProductRepository;
use Webkul\Customer\Repositories\WishlistRepository;
use Cart;
use Auth;
/**
@ -26,13 +28,15 @@ class WishlistController extends Controller
protected $wishlist;
protected $product;
/**
* Initializes the required repository instances.
*
* @param $customer
* @param $wishlist
*/
public function __construct(CustomerRepository $customer, WishlistRepository $wishlist)
public function __construct(CustomerRepository $customer, WishlistRepository $wishlist, ProductRepository $product)
{
$this->middleware('customer');
@ -41,6 +45,8 @@ class WishlistController extends Controller
$this->customer = $customer;
$this->wishlist = $wishlist;
$this->product = $product;
}
/**
@ -67,6 +73,15 @@ class WishlistController extends Controller
* @param integer $itemId
*/
public function add($itemId) {
$product = $this->product->findOneByField('id', $itemId);
if($product->type == "configurable") {
$slug = $product->url_key;
session()->flash('warning', trans('customer::app.wishlist.select-options'));
return redirect()->route('shop.products.index', $slug);
}
$data = [
'channel_id' => core()->getCurrentChannel()->id,
@ -111,12 +126,45 @@ class WishlistController extends Controller
}
}
/**
* Add the configurable product
* to the wishlist.
*
* @return response
*/
public function addconfigurable($urlkey) {
dd($urlkey);
session()->flash('warning', trans('Select options before adding to wishlist'));
return redirect()->route('shop.products.index', $urlkey);
}
/**
* Function to move item from wishlist to cart.
*
* @param integer $itemId
*/
public function moveToCart() {
dd('adding item to wishlist');
public function moveAll() {
Cart::moveAllToCart();
}
/**
* Function to move item from wishlist to cart.
*
* @param integer $itemId
*/
public function move($productId) {
$result = Cart::moveToCart($productId);
$wishlist = $this->wishlist->findWhere(['customer_id' => auth()->guard('customer')->user()->id, 'product_id' => $productId]);
if($this->wishlist->delete($wishlist[0]->id)) {
session()->flash('success', 'Item Moved To Cart Successfully');
return redirect()->back();
} else {
session()->flash('error', 'Item Cannot Be Moved To Cart Successfully');
return redirect()->back();
}
}
}

View File

@ -7,6 +7,7 @@ return [
'already' => 'Item Already Present In Your Wishlist',
'removed' => 'Item Successfully Added To Wishlist',
'remove-fail' => 'Item Cannot Be Removed From Wishlist',
'empty' => 'You Don\'t Have Any Items In Your Wishlist'
'empty' => 'You Don\'t Have Any Items In Your Wishlist',
'select-options' => 'Need To Select Options Before Adding To Wishlist'
],
];

View File

@ -7,7 +7,7 @@ class Review extends AbstractProduct
/**
* Returns the product's avg rating
*
* @param Product $product
* @param Product $product
* @return float
*/
public function getReviews($product)
@ -18,7 +18,7 @@ class Review extends AbstractProduct
/**
* Returns the product's avg rating
*
* @param Product $product
* @param Product $product
* @return float
*/
public function getAverageRating($product)

View File

@ -119,6 +119,10 @@ Route::group(['middleware' => ['web']], function () {
Route::get('wishlist/remove/{id}', 'Webkul\Customer\Http\Controllers\WishlistController@remove')->name('customer.wishlist.remove');
Route::get('wishlist/move/{id}', 'Webkul\Customer\Http\Controllers\WishlistController@move')->name('customer.wishlist.move');
Route::get('wishlist/moveall', 'Webkul\Customer\Http\Controllers\WishlistController@moveAll')->name('customer.wishlist.moveall');
//customer account
Route::prefix('account')->group(function () {

View File

@ -44,7 +44,6 @@
.addtocart {
margin-right: 10px;
text-transform: uppercase;
}
.add-to-wishlist {

View File

@ -40,7 +40,7 @@
<div class="operations">
<a class="mb-50" href="{{ route('customer.wishlist.remove', $item->id) }}"><span class="icon trash-icon"></span></a>
<button class="btn btn-primary btn-md">{{ __('shop::app.wishlist.move-to-cart') }}</button>
<a href="{{ route('customer.wishlist.move', $item->id) }}" class="btn btn-primary btn-md">{{ __('shop::app.wishlist.move-to-cart') }}</a>
</div>
</div>
<div class="horizontal-rule mb-10 mt-10"></div>

View File

@ -277,35 +277,10 @@
var layerFilter = document.getElementsByClassName('responsive-layred-filter')[0];
var navResponsive = document.getElementsByClassName('responsive-nav')[0];
var thumbList = document.getElementsByClassName('thumb-list')[0];
var thumbFrame = document.getElementsByClassName('thumb-frame');
var productHeroImage = document.getElementsByClassName('product-hero-image')[0];
search.addEventListener("click", header);
hamMenu.addEventListener("click", header);
// activate on window resize
window.addEventListener('resize', function(){
if(window.innerWidth > 720){
searchResponsive.style.display = 'none';
navResponsive.style.display = 'none';
if(layerFilter && sortLimit){
layerFilter.style.display ="none";
sortLimit.style.display ="none";
}
}
if(window.innerWidth < 1313 && window.innerWidth > 720){
if(thumbList){
thumbList.style.maxHeight = productHeroImage.offsetHeight + "px";
for(let i=0 ; i < thumbFrame.length ; i++){
thumbFrame[i].style.height = (productHeroImage.offsetHeight/4) + "px";
}
}
}else {
for(let i=0 ; i < thumbFrame.length ; i++){
thumbFrame[i].style.height = 120 + "px";
}
}
});
// for header responsive icon
function header(){

View File

@ -33,6 +33,7 @@
@else
@if($product->type == "configurable")
<a href="{{ route('cart.add.configurable', $product->url_key) }}" class="btn btn-lg btn-primary addtocart">{{ __('shop::app.home.product-card.add-to-cart') }}</a>
@include('shop::products.wishlist')
@else
<div class="cart-wish-wrap">
<form action="{{route('cart.add', $product->id)}}" method="POST">

View File

@ -65,52 +65,14 @@
</accordian>
@include ('shop::products.view.attributes')
@include ('shop::products.view.reviews')
</div>
</form>
</div>
@include ('shop::products.view.up-sells')
</section>
@endsection
@push('scripts')
<script>
document.onreadystatechange = function () {
var state = document.readyState
var galleryTemplate = document.getElementById('product-gallery-template');
var addTOButton = document.getElementsByClassName('add-to-buttons')[0];
if(galleryTemplate){
if (state == 'interactive') {
galleryTemplate.style.display="none";
} else {
document.getElementById('loader').style.display="none";
addTOButton.style.display="flex";
}
}
}
$(document).ready(function() {
var thumbList = document.getElementsByClassName('thumb-list')[0];
var thumbFrame = document.getElementsByClassName('thumb-frame');
var productHeroImage = document.getElementsByClassName('product-hero-image')[0];
// for product page resize image
if(thumbList && productHeroImage){
thumbList.style.maxHeight = productHeroImage.offsetHeight + "px";
for(let i=0 ; i < thumbFrame.length ; i++){
thumbFrame[i].style.height = (productHeroImage.offsetHeight/4) + "px";
}
}
})
</script>
@endpush

View File

@ -1,5 +1,5 @@
@auth('customer')
<a class="add-to-wishlist" href="{{ route('customer.wishlist.add', $product->id) }}">
<span class="icon wishlist-icon"></span>
</a>
<a class="add-to-wishlist" href="{{ route('customer.wishlist.add', $product->id) }}">
<span class="icon wishlist-icon"></span>
</a>
@endauth

View File

@ -97,8 +97,6 @@
height: 32px;
}
<<<<<<< HEAD
=======
.icon-arrow-up {
background-image: url("../images/arrow-up.svg");
width: 16px;
@ -123,49 +121,6 @@
height: 18px;
}
.product-grid-4 {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
grid-auto-rows: auto;
grid-column-gap: 48px;
grid-row-gap: 15px;
}
.product-grid-3 {
display: grid;
grid-template-columns: repeat(auto-fill, minmax(235px, 1fr));
grid-gap: 27px;
grid-auto-rows: auto;
}
@media only screen and (max-width: 854px) {
.product-grid-4 {
grid-template-columns: 29.5% 29.5% 29.5%;
grid-column-gap: 35px;
}
}
@media only screen and (max-width: 653px) {
.product-grid-4 {
grid-template-columns: 48.5% 48.5%;
grid-column-gap: 17px;
}
}
@media only screen and (max-width: 425px) {
.product-card {
font-size: 90%;
}
.product-card .btn.btn-md {
padding: 5px;
}
.product-grid-4 {
grid-template-columns: 48.5% 48.5%;
grid-column-gap: 10px;
}
}
>>>>>>> 0b9568132497b959c68dbcbf51488f2780f13c0d
.product-card .product-image {
max-height: 350px;
max-width: 280px;

File diff suppressed because one or more lines are too long

View File

@ -1,4 +1,4 @@
{
"/js/shop.js": "/js/shop.js",
"/css/shop.css": "/css/shop.css"
}
}