Skip to content

Commit

Permalink
Merge in Dev
Browse files Browse the repository at this point in the history
  • Loading branch information
alecritson committed Jan 22, 2021
1 parent 0112092 commit ff22bd1
Show file tree
Hide file tree
Showing 71 changed files with 957 additions and 208 deletions.
3 changes: 2 additions & 1 deletion database/factories/ProductFactory.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

use Faker\Generator as Faker;
use GetCandy\Api\Core\Products\Models\Product;

/*
|--------------------------------------------------------------------------
Expand All @@ -13,7 +14,7 @@
|
*/

$factory->define(GetCandy\Api\Core\Products\Models\Product::class, function (Faker $faker) {
$factory->define(Product::class, function (Faker $faker) {
return [
'attribute_data' => [
'name' => [
Expand Down
22 changes: 22 additions & 0 deletions database/factories/ProductVariantFactory.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

use Faker\Generator as Faker;

/*
|--------------------------------------------------------------------------
| Model Factories
|--------------------------------------------------------------------------
|
| This directory should contain each of the model factory definitions for
| your application. Factories provide a convenient way to generate new
| model instances for testing / seeding your application's database.
|
*/

$factory->define(GetCandy\Api\Core\Products\Models\ProductVariant::class, function (Faker $faker) {
return [
'sku' => $faker->unique()->slug,
'stock' => $faker->numberBetween(10, 2000),
'price' => $faker->randomNumber(2),
];
});
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ public function up()

$families = ProductFamily::all();

if (Schema::hasColumn('product_families', 'name')) {
Schema::table('product_families', function (Blueprint $table) {
$table->dropColumn('name');
});
Schema::table('product_families', function (Blueprint $table) {
$table->text('name')->nullable();
});
}

foreach ($families as $family) {
$data = json_decode($family->attribute_data, true);
$name = $data['name'][$channel->handle]['en'];
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreatePaymentProviderUsersTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('payment_provider_users', function (Blueprint $table) {
$table->id();

$userIdColType = Schema::getColumnType('users', 'id');

if ($userIdColType == 'integer') {
$table->unsignedInteger('user_id');
$table->foreign('user_id')->references('id')->on('users');
} else {
$table->foreignId('user_id')->constrained();
}

$table->string('provider_id')->index();
$table->string('provider')->index();
$table->timestamps();
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::table('reusable_payments', function (Blueprint $table) {
$table->dropColumn('meta');
});
}
}
36 changes: 18 additions & 18 deletions openapi/baskets/paths/baskets.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,21 @@ get:
description: Get a paginated list of baskets
tags:
- Baskets
# post:
# summary: Create Basket
# operationId: post-baskets
# responses:
# '200':
# description: OK
# content:
# application/json:
# schema:
# $ref: '../responses/BasketResponse.yaml'
# requestBody:
# content:
# application/json:
# schema:
# $ref: '../requests/CreateBasketBody.yaml'
# tags:
# - Baskets
# description: ''
post:
summary: Create Basket
operationId: post-baskets
responses:
'200':
description: OK
content:
application/json:
schema:
$ref: '../responses/BasketResponse.yaml'
requestBody:
content:
application/json:
schema:
$ref: '../requests/CreateBasketBody.yaml'
tags:
- Baskets
description: ''
5 changes: 3 additions & 2 deletions routes/api.client.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
$router->get('collections/{id}', 'Collections\CollectionController@show');
$router->get('categories/{id}', 'Categories\CategoryController@show');
$router->get('products/recommended', 'Products\ProductController@recommended');
$router->get('products/{product}', 'Products\ProductController@show');
$router->get('products/{encoded_id}', '\GetCandy\Api\Core\Products\Actions\FetchProduct');
$router->get('products', 'Products\ProductController@index');

/*
Expand Down Expand Up @@ -49,8 +49,9 @@
*/
$router->post('basket-lines', 'Baskets\BasketLineController@store');
$router->put('basket-lines/{id}', 'Baskets\BasketLineController@update');
$router->delete('basket-lines/{id}', 'Baskets\BasketLineController@destroyLine');
$router->post('basket-lines/{id}/add', 'Baskets\BasketLineController@addQuantity');
$router->post('basket-lines/{id}/remove', 'Baskets\BasketLineController@removeQuantity');
$router->put('basket-lines/{id}/remove', 'Baskets\BasketLineController@removeQuantity');
$router->delete('basket-lines', 'Baskets\BasketLineController@destroy');

/*
Expand Down
3 changes: 2 additions & 1 deletion src/Core/Addresses/Actions/UpdateAddressAction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GetCandy\Api\Core\Addresses\Models\Address;
use GetCandy\Api\Core\Addresses\Resources\AddressResource;
use GetCandy\Api\Core\Countries\Actions\FetchCountry;
use GetCandy\Api\Core\Countries\Models\Country;
use Illuminate\Support\Arr;
use Lorisleiva\Actions\Action;

Expand Down Expand Up @@ -55,7 +56,7 @@ public function rules()
'city' => 'string',
'state' => 'string',
'postal_code' => 'string',
'country_id' => 'hashid_is_valid:countries',
'country_id' => 'hashid_is_valid:'.Country::class,
'shipping' => 'boolean',
'billing' => 'boolean',
'default' => 'boolean',
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Addresses/Policies/AddressPolicy.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class AddressPolicy
*/
public function create(?User $user)
{
return $user->can('create-address');
return true;
}

public function update(?User $user, Address $address)
Expand Down
10 changes: 8 additions & 2 deletions src/Core/Assets/Drivers/BaseUrlDriver.php
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ public function process(array $data, Model $model = null)

$asset = $this->prepare();

$asset->save();

if ($model) {
if ($model->assets()->count()) {
// Get anything that isn't an "application";
Expand All @@ -74,10 +76,14 @@ public function process(array $data, Model $model = null)
} else {
$asset->primary = true;
}
$model->assets()->attach($asset);
$asset->save();
$model->assets()->attach($asset, [
'primary' => ! $model->assets()->images()->exists(),
'assetable_type' => get_class($model),
'position' => $model->assets()->count() + 1,
]);
}

$asset->save();
dispatch(new GenerateTransforms($asset));

return $asset;
Expand Down
14 changes: 12 additions & 2 deletions src/Core/Assets/Services/AssetTransformService.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use GetCandy\Api\Core\Assets\Models\Transform;
use GetCandy\Api\Core\Scaffold\BaseService;
use Illuminate\Contracts\Filesystem\FileNotFoundException;
use Illuminate\Support\Facades\DB;
use Image;
use Intervention\Image\Exception\NotReadableException;
use Storage;
Expand Down Expand Up @@ -92,10 +93,19 @@ protected function process($transformer, $asset)
$assetTransform->asset()->associate($asset);
$assetTransform->transform()->associate($transformer);

$filename = $transformer->handle.'_'.($asset->external ? $asset->location.'.jpg' : $asset->filename);

$i = 1;

while (DB::table('asset_transforms')->where('filename', '=', $filename)->exists()) {
$name = pathinfo($filename, PATHINFO_FILENAME);
$ext = pathinfo($filename, PATHINFO_EXTENSION);
$filename = "{$name}_{$i}.{$ext}";
}

$assetTransform->location = $thumbPath;
$assetTransform->filename = $transformer->handle.'_'.($asset->external ? $asset->location.'.jpg' : $asset->filename);
$assetTransform->filename = $filename;
$assetTransform->file_exists = true;

$assetTransform->save();

Storage::disk($source->disk)->put(
Expand Down
8 changes: 7 additions & 1 deletion src/Core/Attributes/Actions/FetchAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public function authorize()
*/
public function rules()
{
return [];
return [
'handles' => 'nullable|array|min:0',
];
}

/**
Expand All @@ -34,6 +36,10 @@ public function rules()
*/
public function handle()
{
if ($this->handles) {
return Attribute::whereIn('handle', $this->handles)->get();
}

return Attribute::get();
}
}
16 changes: 14 additions & 2 deletions src/Core/Categories/Drafting/CategoryDrafter.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,20 @@ public function publish(Model $category)

// Delete routes
$parent->routes()->delete();
$parent->forceDelete();

// Move any direct children on to the published category
DB::transaction(function ($query) use ($parent, $category) {
$parent->children->each(function ($node) use ($category) {
$node->parent()->associate($category)->save();
});
});

$parent->update([
'_lft' => null,
'_rgt' => null,
]);
$parent->refresh()->forceDelete();
// $parent->refresh()->forceDelete();

$category->drafted_at = null;
$category->save();
Expand All @@ -62,7 +75,6 @@ public function publish(Model $category)
]);
}


event(new ModelPublishedEvent($category));

return $category;
Expand Down
2 changes: 1 addition & 1 deletion src/Core/Categories/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Category extends BaseModel
* @var array
*/
protected $fillable = [
'attribute_data', 'parent_id',
'attribute_data', 'parent_id', 'sort', 'range', '_lft', '_rgt',
];

public function getParentIdAttribute($val)
Expand Down
35 changes: 35 additions & 0 deletions src/Core/Categories/Observers/CategoryObserver.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

namespace GetCandy\Api\Core\Categories\Observers;

use GetCandy\Api\Core\Assets\Services\AssetService;
use GetCandy\Api\Core\Categories\Models\Category;
use GetCandy\Api\Core\Search\SearchManager;

class CategoryObserver
{
/**
* @var \GetCandy\Api\Core\Assets\Services\AssetService
*/
protected $assets;

protected $search;

public function __construct(AssetService $assets, SearchManager $search)
{
$this->assets = $assets;
$this->search = $search;
}

/**
* Handle the User "deleted" event.
*
* @param \GetCandy\Api\Core\Categories\Models\Category $category
* @return void
*/
public function deleted(Category $category)
{
$driver = $this->search->with(config('getcandy.search.driver'));
$driver->delete($category);
}
}
2 changes: 1 addition & 1 deletion src/Core/Categories/QueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function withDepth($as = 'depth')
->selectRaw('count(1) - 1')
->from($this->model->getTable().' as '.$alias)
->where(function ($query) use ($table, $lft, $rgt, $wrappedAlias) {
$query->whereNull('drafted_at')
$query->whereNull($this->model->getTable().'.drafted_at')
->whereRaw("{$table}.{$lft} between {$wrappedAlias}.{$lft} and {$wrappedAlias}.{$rgt}");
});

Expand Down
18 changes: 16 additions & 2 deletions src/Core/Discounts/Models/DiscountCriteriaItem.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace GetCandy\Api\Core\Discounts\Models;

use GetCandy;
use GetCandy\Api\Core\Customers\Models\CustomerGroup;
use GetCandy\Api\Core\Products\Models\Product;
use GetCandy\Api\Core\Scaffold\BaseModel;
Expand Down Expand Up @@ -31,9 +32,22 @@ public function saveEligible($type, $id)
{
$relation = camel_case(str_plural($type));

$typeModel = GetCandy::getUserModel();

if (method_exists($this, $relation)) {
$realId = (new $typeModel)->decodeId($id);
$this->{$relation}()->sync($realId);
}
}

public function saveEligibles($type, array $ids)
{
$relation = camel_case(str_plural($type));
$userModel = GetCandy::getUserModel();
if (method_exists($this, $relation)) {
$realId = (new $type)->decodedId($id);
$this->{$relation}()->attach($realId);
$this->{$relation}()->sync(
(new $userModel)->decodeIds($ids)
);
}
}

Expand Down
Loading

0 comments on commit ff22bd1

Please sign in to comment.