Skip to content

Commit

Permalink
Merge pull request #210 from avored/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
indpurvesh authored Feb 2, 2023
2 parents 01b1c7e + ed3152d commit 4e543c9
Show file tree
Hide file tree
Showing 18 changed files with 5,471 additions and 2,435 deletions.
3 changes: 3 additions & 0 deletions config/avored.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
use AvoRed\Framework\Graphql\Mutations\Auth\ResetPasswordMutation;
use AvoRed\Framework\Graphql\Mutations\Cart\UpdateCartMutation;
use AvoRed\Framework\Graphql\Queries\ProductQuery;
use AvoRed\Framework\Graphql\Types\TokenType;
use AvoRed\Framework\System\Controllers\AvoRedGraphQLController;

return [
Expand Down Expand Up @@ -129,6 +130,8 @@
],

'types' => [
'Token' => TokenType::class,
\Rebing\GraphQL\Support\UploadType::class,
'Category' => CategoryType::class,
'Product' => ProductType::class,
'Customer' => CustomerType::class,
Expand Down
7,709 changes: 5,317 additions & 2,392 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"axios": "^0.21.4",
"easymde": "^2.18.0",
"feather-icons": "^4.28.0",
"laravel-mix": "^6.0.49",
"laravel-mix": "^6.0.15",
"postcss": "^8.3.6",
"tailwindcss": "^3.1.8"
},
Expand Down
2 changes: 1 addition & 1 deletion resources/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ Alpine.data('app', () => ({
}
})
this.showConfirmationModal = false
}
},
init() {
console.log('sdfds')
}
Expand Down
23 changes: 23 additions & 0 deletions resources/views/catalog/product/cards/property.blade.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
@foreach($productProperties as $property)

@switch($property->field_type)
@case('SELECT')
<div class="mt-3">
<x-avored::form.select
name="properties[{{ $property->id }}]"
label="{{ $property->name }}"
>
<option value="">{{ __('avored::system.please_select') }}</option>
@foreach ($property->getDropdownOptions() as $dropdownOption)
<option {{ (isset($product) && $product->categories->contains(Arr::get($dropdownOption, 'value'))) ? 'selected' : ''}} value="{{ Arr::get($dropdownOption, 'value') }}">
{{ Arr::get($dropdownOption, 'label') }}
</option>
@endforeach

</x-avored::form.select>
</div>
@break

@endswitch

@endforeach
2 changes: 1 addition & 1 deletion src/Cart/CartManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public function add(string $slug, float $qty = 1, array $attributes = []): CartP
$cartProduct->save();
} else {
$data = [
'visitor_id' => $this->visitor,
'visitor_id' => $this->visitor(),
'product_id' => $product->id,
'qty' => $qty
];
Expand Down
18 changes: 17 additions & 1 deletion src/Catalog/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AvoRed\Framework\Catalog\Requests\ProductRequest;
use AvoRed\Framework\Database\Contracts\CategoryModelInterface;
use AvoRed\Framework\Database\Contracts\ProductModelInterface;
use AvoRed\Framework\Database\Contracts\PropertyModelInterface;
use AvoRed\Framework\Database\Models\Document;
use AvoRed\Framework\Database\Models\Product;
use AvoRed\Framework\Tab\Tab;
Expand All @@ -24,17 +25,26 @@ class ProductController extends Controller
* @var AvoRed\Framework\Database\Repository\CategoryRepository $categoryRepository
*/
protected $categoryRepository;

/**
* @var AvoRed\Framework\Database\Repository\PropertyRepository $propertyRepository
*/
protected $propertyRepository;

/**
*
* @param ProductRepositroy $repository
* @param CategoryRepositroy $categoryRepository
* @param PropertyRepositroy $propertyRepository
*/
public function __construct(
ProductModelInterface $repository,
CategoryModelInterface $categoryRepository
CategoryModelInterface $categoryRepository,
PropertyModelInterface $propertyRepository
) {
$this->productRepository = $repository;
$this->categoryRepository = $categoryRepository;
$this->propertyRepository = $propertyRepository;
}

/**
Expand Down Expand Up @@ -91,13 +101,17 @@ public function edit(Product $product)
{
$tabs = Tab::get('catalog.product');
$options = $this->categoryRepository->options();
$productProperties = $this->propertyRepository->getAllProductProperties();

// $displayAsOptions = Product::DISPLAY_AS;
$tabs = Tab::get('catalog.product');


return view('avored::catalog.product.edit')
// ->with('displayAsOptions', $displayAsOptions)
->with('tabs', $tabs)
->with('options', $options)
->with('productProperties', $productProperties)
->with('product', $product);
}

Expand All @@ -112,6 +126,8 @@ public function update(ProductRequest $request, Product $product)
{
$product->update($request->all());
$this->productRepository->saveProductCategories($product, $request);

dd($request->all());
return redirect(route('admin.product.index'));
}

Expand Down
9 changes: 9 additions & 0 deletions src/Database/Contracts/PropertyModelInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@

namespace AvoRed\Framework\Database\Contracts;

use Illuminate\Support\Collection;

interface PropertyModelInterface extends BaseInterface
{

/**
* Get all the properties which should apply to all the products.
* @param int $perPage
* @return \Illuminate\Support\Collection $products
*/
public function getAllProductProperties(): Collection;
}
12 changes: 10 additions & 2 deletions src/Database/Models/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,10 @@ public function getFullNameAttribute()
*/
public function getImagePathUrlAttribute()
{
if ($this->attributes['image_path'] === null) {
if ($this->imagePath === null) {
return 'https://placehold.it/250x250';
}
return asset('storage/'.$this->attributes['image_path']);
return asset('storage/'. $this->imagePath->path);
}

/**
Expand Down Expand Up @@ -150,4 +150,12 @@ public function orderComments()
{
// <!-- return $this->morphMany(OrderComment::class, 'commentable'); -->
}

/**
* Get the staff profile image.
*/
public function imagePath()
{
return $this->morphOne(Document::class, 'documentable');
}
}
10 changes: 10 additions & 0 deletions src/Database/Repository/PropertyRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use AvoRed\Framework\Database\Models\Property;
use AvoRed\Framework\Database\Contracts\PropertyModelInterface;
use AvoRed\Framework\Database\Traits\FilterTrait;
use Illuminate\Support\Collection;

class PropertyRepository extends BaseRepository implements PropertyModelInterface
{
Expand Down Expand Up @@ -42,6 +43,15 @@ public function model(): Property
return $this->model;
}

/**
* Get all the properties which should apply to all the products.
* @return \Illuminate\Support\Collection $products
*/
public function getAllProductProperties(): Collection
{
return $this->model()->where('use_for_all_products', true)->get();
}


public function savePropertyDropdown($request , $property)
{
Expand Down
9 changes: 1 addition & 8 deletions src/Graphql/Mutations/Auth/LoginMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,13 @@ public function args(): array

public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
{
$data = [];

$customer = $this->customerRepository->findByEmail($args['email']);
$client = $customer->getPassportClient();

if (null !== $client && $client instanceof Client) {
$serverRequest = $this->createRequest($client, $customer->id, $args, $scope = []);
$reponse = app(AccessTokenController::class)->issueToken($serverRequest);
$data = json_decode($reponse->content(), true);

$customer->token_type = $data['token_type'];
$customer->expires_in = $data['expires_in'];
$customer->access_token = $data['access_token'];
$customer->refresh_token = $data['refresh_token'];
$customer->token_info = json_decode($reponse->content());

return $customer;
}
Expand Down
7 changes: 1 addition & 6 deletions src/Graphql/Mutations/Auth/RegisterMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,12 +93,7 @@ public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closur
if (null !== $client && $client instanceof Client) {
$serverRequest = $this->createRequest($client, $customer->id, $args, $scope = []);
$reponse = app(AccessTokenController::class)->issueToken($serverRequest);
$data = json_decode($reponse->content(), true);

$customer->token_type = $data['token_type'];
$customer->expires_in = $data['expires_in'];
$customer->access_token = $data['access_token'];
$customer->refresh_token = $data['refresh_token'];
$customer->token_info = json_decode($reponse->content());

return $customer;
}
Expand Down
14 changes: 13 additions & 1 deletion src/Graphql/Mutations/Customer/CustomerUpdateMutation.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

use AvoRed\Framework\Database\Contracts\CustomerModelInterface;
use AvoRed\Framework\Database\Models\Customer;
use AvoRed\Framework\Document\Document;
use AvoRed\Framework\Graphql\Traits\AuthorizedTrait;
use Closure;
use GraphQL\Type\Definition\ResolveInfo;
Expand Down Expand Up @@ -53,13 +54,24 @@ public function args(): array
'name' => 'last_name',
'type' => Type::nonNull(Type::string())
],
'profile_image' => [
'name' => 'profile_image',
'type' => GraphQL::type('Upload'),
],
];
}

public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closure $getSelectFields)
{
/** @var \Avored\Framework\Database\Models\Customer $customer */
$customer = Auth::guard('customer')->user();


if (isset($args['profile_image'])) {
$document = Document::uploadPublicly($args['profile_image']);
$customer->imagePath()->updateOrCreate(optional($customer->imagePath)->toArray() ?? [], $document);
}

dd('fixed this one');
$customer->update($args);

return $customer;
Expand Down
2 changes: 2 additions & 0 deletions src/Graphql/Queries/CustomerQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ public function resolve($root, $args, $context, ResolveInfo $resolveInfo, Closur
return $this->customerRepository->find($args['id']);
}

dd(Auth::guard('customer')->user()->image_path_url);

return $this->customerRepository->find(Auth::guard('customer')->user()->id);
}
}
29 changes: 13 additions & 16 deletions src/Graphql/Types/CustomerType.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
use Rebing\GraphQL\Support\Type as GraphQLType;
use GraphQL\Type\Definition\Type;
use Rebing\GraphQL\Support\Facades\GraphQL;
use stdClass;

class CustomerType extends GraphQLType
{
Expand Down Expand Up @@ -35,6 +36,14 @@ public function fields(): array
'type' => Type::string(),
'description' => 'The customer for the email'
],
'image_path' => [
'type' => Type::string(),
'description' => 'The customer for the image path'
],
'image_path_url' => [
'type' => Type::string(),
'description' => 'The customer for the image path url'
],
'id' => [
'type' => Type::string(),
'description' => 'The customer for the id'
Expand All @@ -47,25 +56,13 @@ public function fields(): array
'type' => Type::string(),
'description' => 'Customer updated at'
],
'token_type' => [
'type' => Type::string(),
'description' => 'Customer updated at'
],
'expires_in' => [
'type' => Type::int(),
'description' => 'Customer updated at'
],
'access_token' => [
'type' => Type::string(),
'description' => 'Customer updated at'
],
'refresh_token' => [
'type' => Type::string(),
'description' => 'Customer updated at'
'token_info' => [
'type' => GraphQL::type('Token'),
'description' => 'Customer Token Information'
],
'addresses' => [
'type' => Type::listOf(GraphQL::type('Address')),
'description' => 'Customer updated at'
'description' => 'Customer Address List'
],
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/Graphql/Types/ProductType.php
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ public function fields(): array
*/
protected function resolveMainImageUrlField($product, $args)
{
$document = $product->document()->first();
$document = $product->documents()->first();

if (is_null($document)) {
$color = str_pad(dechex(rand(0x000000, 0xFFFFFF)), 6, 0, STR_PAD_LEFT);
Expand Down
43 changes: 43 additions & 0 deletions src/Graphql/Types/TokenType.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php
namespace AvoRed\Framework\Graphql\Types;

use Rebing\GraphQL\Support\Type as GraphQLType;
use GraphQL\Type\Definition\Type;

class TokenType extends GraphQLType
{
/**
* Attribute for Token Type
* @var array
*/
protected $attributes = [
'name' => 'Token',
'description' => 'A type'
];

/**
* Fields for Token Type
* @return array $fields
*/
public function fields(): array
{
return [
'token_type' => [
'type' => Type::string(),
'description' => 'Customer updated at'
],
'expires_in' => [
'type' => Type::int(),
'description' => 'Customer updated at'
],
'access_token' => [
'type' => Type::string(),
'description' => 'Customer updated at'
],
'refresh_token' => [
'type' => Type::string(),
'description' => 'Customer updated at'
],
];
}
}
10 changes: 5 additions & 5 deletions src/Tab/TabProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ public function registerTabs()
->view('avored::catalog.product.cards.images');
});

// Tab::put('catalog.product', function (TabItem $tab) {
// $tab->key('catalog.product.property')
// ->label('avored::system.tab.property')
// ->view('avored::catalog.product.cards.property');
// });
Tab::put('catalog.product', function (TabItem $tab) {
$tab->key('catalog.product.property')
->label('avored::system.property')
->view('avored::catalog.product.cards.property');
});

// Tab::put('catalog.product', function (TabItem $tab) {
// $tab->key('catalog.product.attribute')
Expand Down

0 comments on commit 4e543c9

Please sign in to comment.