Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
vishal-webkul committed Mar 13, 2021
1 parent ba6920e commit 1bb932b
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 12 deletions.
2 changes: 1 addition & 1 deletion publishable/assets/js/app.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion publishable/assets/mix-manifest.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"/js/app.js": "/js/app.js?id=4da03409f21eb650589d",
"/js/app.js": "/js/app.js?id=899a90acfbec8ab03f16",
"/css/pwa-admin.css": "/css/pwa-admin.css?id=7073d876ccd90f556cb1",
"/css/pwa.css": "/css/pwa.css?id=985298ea84b30351141c"
}
88 changes: 88 additions & 0 deletions src/Http/Controllers/Shop/AddressController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
<?php

namespace Webkul\PWA\Http\Controllers\Shop;

use Webkul\Customer\Repositories\CustomerAddressRepository;
use Webkul\API\Http\Controllers\Shop\Controller;
use Webkul\API\Http\Resources\Customer\CustomerAddress as CustomerAddressResource;

class AddressController extends Controller
{
/**
* Contains current guard
*
* @var array
*/
protected $guard;

/**
* Contains route related configuration
*
* @var array
*/
protected $_config;

/**
* CustomerAddressRepository object
*
* @var \Webkul\Customer\Repositories\CustomerAddressRepository
*/
protected $customerAddressRepository;

/**
* Controller instance
*
* @param Webkul\Customer\Repositories\CustomerAddressRepository $customerAddressRepository
*/
public function __construct(CustomerAddressRepository $customerAddressRepository)
{
$this->guard = request()->has('token') ? 'api' : 'customer';

auth()->setDefaultDriver($this->guard);

// $this->middleware('auth:' . $this->guard);

$this->_config = request('_config');

$this->customerAddressRepository = $customerAddressRepository;
}

/**
* Store a newly created resource in storage.
*
* @return \Illuminate\Http\Response
*/
public function store()
{
$customer = auth($this->guard)->user();

if (request()->input('address1') && ! is_array(request()->input('address1'))) {
return response()->json([
'message' => 'address1 must be an array.',
]);
}

if (request()->input('address1')) {
request()->merge([
'address1' => implode(PHP_EOL, array_filter(request()->input('address1'))),
'customer_id' => $customer->id,
]);
}

$this->validate(request(), [
'address1' => 'string|required',
'country' => 'string|required',
'state' => 'string|required',
'city' => 'string|required',
'postcode' => 'required',
'phone' => 'required',
]);

$customerAddress = $this->customerAddressRepository->create(request()->all());

return response()->json([
'message' => 'Your address has been created successfully.',
'data' => new CustomerAddressResource($customerAddress),
]);
}
}
13 changes: 12 additions & 1 deletion src/Http/Controllers/Shop/CartController.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,11 +111,22 @@ public function store($id)
if (request()->get('is_buy_now')) {
Event::dispatch('shop.item.buy-now', $id);
}
$data = request()->all();

if (isset($data['links'])) {
$tempLinks = $data['links'];
$temArray = [];
unset($data['links']);
foreach ($tempLinks as $key => $value) {
array_push($temArray, $key);
}
$data['links'] = $temArray;
}

Event::dispatch('checkout.cart.item.add.before', $id);

try {
$result = Cart::addProduct($id, request()->except('_token'));
$result = Cart::addProduct($id, $data);

if (is_array($result) && isset($result['warning'])) {
return response()->json([
Expand Down
23 changes: 22 additions & 1 deletion src/Http/Resources/Catalog/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,26 @@ public function toArray($request)
$data['show_quantity_changer'] = $product->getTypeInstance()->showQuantityBox();
}

$pwa_images = productimage()->getGalleryImages($product);
$pwa_videos = productvideo()->getVideos($product);

$pwa_videoData = $pwa_imageData = [];

foreach ($pwa_videos as $key => $video) {
$pwa_videoData[$key]['type'] = $video['type'];
$pwa_videoData[$key]['large_image_url'] = $pwa_videoData[$key]['small_image_url']= $pwa_videoData[$key]['medium_image_url']= $pwa_videoData[$key]['original_image_url'] = $video['video_url'];
}

foreach ($pwa_images as $key => $image) {
$pwa_imageData[$key]['type'] = '';
$pwa_imageData[$key]['large_image_url'] = $image['large_image_url'];
$pwa_imageData[$key]['small_image_url'] = $image['small_image_url'];
$pwa_imageData[$key]['medium_image_url'] = $image['medium_image_url'];
$pwa_imageData[$key]['original_image_url'] = $image['original_image_url'];
}

$pwa_images = array_merge($pwa_imageData, $pwa_videoData);

$data += [
'id' => $product->id,
'type' => $product->type,
Expand All @@ -139,7 +159,8 @@ public function toArray($request)
'short_description' => $this->short_description,
'description' => $this->description,
'sku' => $this->sku,
'images' => ProductImage::collection($product->images),
'images' => $pwa_images,
'videos' => productvideo()->getVideos($product),
'base_image' => productimage()->getProductBaseImage($product),
'variants' => Self::collection($this->variants),
'in_stock' => $product->haveSufficientQuantity(1),
Expand Down
2 changes: 2 additions & 0 deletions src/Http/routes.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@
Route::post('reviews/{id}/create', 'ReviewController@store');

Route::get('advertisements', 'API\APIController@fetchAdvertisementImages');

Route::post('save-address', 'AddressController@store');
});

// Checkout routes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
EventBus.$emit('show-ajax-loader');
this.$http.post('/api/addresses/create', this.address)
this.$http.post('/api/save-address', this.address)
.then(function(response) {
this_this.loading = false;
Expand Down
22 changes: 16 additions & 6 deletions src/Resources/assets/js/components/products/gallery-images.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,16 @@
v-if="product.images.length"
v-for="image in product.images"
>
<img
alt="original-image-url"
:src="image.original_image_url"
/>
<div>
<video v-if="image.type == 'video'" :src="image.small_image_url" type="video/mp4" width="100%" height="200px" controls>
Not Supported
</video>

<img v-else
alt="original-image-url"
:src="image.original_image_url"
/>
</div>
</slide>

<slide v-if="! product.images.length">
Expand All @@ -28,14 +34,18 @@

<script>
import { Carousel, Slide } from 'vue-carousel';
export default {
name: 'gallery-images',
components: { Carousel, Slide },
props: ['product']
props: ['product'],
mounted () {
console.log(this.product);
}
}
</script>

<style lang="scss" scoped>
Expand Down
2 changes: 1 addition & 1 deletion src/Resources/assets/js/components/products/index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@
EventBus.$emit('checkout.cart.changed', response.data.data);
if (this.is_buy_now) {
this.$router.push({name: 'cart'})
this.$router.push({name: 'onepage'})
}
})
.catch(error => {
Expand Down

0 comments on commit 1bb932b

Please sign in to comment.