Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v0.3.18 - patched addon category, added product status selection, other patches #36

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .stylelintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@

module.exports = {
extends: ['stylelint-config-standard', 'stylelint-prettier/recommended'],
rules: {
'selector-class-pattern': null,
'no-descending-specificity': null,
'color-function-notation': null,
},
};
8 changes: 6 additions & 2 deletions addon/components/modals/manage-addons.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,12 @@ export default class ModalsManageAddonsComponent extends Component {
owner_uuid: this.activeStore.id,
});

yield category.save();
this.categories.pushObject(category);
try {
yield category.save();
this.categories.pushObject(category);
} catch (error) {
this.notifications.serverError(error);
}
}

/**
Expand Down
3 changes: 2 additions & 1 deletion addon/controllers/products/index/category/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,12 @@ export default class ProductsIndexCategoryNewController extends BaseController {
@service crud;
@service hostRouter;
@alias('storefront.activeStore') activeStore;
@tracked product = this.store.createRecord('product', { store_uuid: this.activeStore.id, currency: this.activeStore.currency, tags: [], meta_array: [] });
@tracked product = this.store.createRecord('product', { store_uuid: this.activeStore.id, currency: this.activeStore.currency, tags: [], meta_array: [], status: 'published' });
@tracked uploadQueue = [];
@tracked uploadedFiles = [];
@tracked primaryFile = null;
@tracked isSaving = false;
@tracked statusOptions = ['published', 'draft'];
abilityPermission = 'storefront create product';

/** overlay options */
Expand Down
23 changes: 0 additions & 23 deletions addon/controllers/products/index/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,9 @@ import { timeout } from 'ember-concurrency';
import { task } from 'ember-concurrency-decorators';

export default class ProductsIndexIndexController extends BaseController {
/**
* Inject the `filters` service
*
* @var {Service}
*/
@service filters;

/**
* Inject the `intl` service
*
* @var {Service}
*/
@service intl;

/**
* Inject the `currentUser` service
*
* @var {Service}
*/
@service currentUser;

/**
* Inject the `currentUser` service
*
* @var {Service}
*/
@service modalsManager;

/**
Expand Down
3 changes: 3 additions & 0 deletions addon/models/product-addon-category.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ export default class ProductAddonCategoryModel extends Model {

/** @attributes */
@attr('string') name;
@attr('number') max_selectable;
@attr('boolean') is_required;
@attr('raw') excluded_addons;

/** @dates */
Expand All @@ -25,6 +27,7 @@ export default class ProductAddonCategoryModel extends Model {
category_uuid: this.category_uuid,
product_uuid: this.product_uuid,
name: this.name,
max_selectable: this.max_selectable,
excluded_addons: getWithDefault(this, 'excluded_addons', []),
updated_at: this.updated_at,
created_at: this.created_at,
Expand Down
7 changes: 7 additions & 0 deletions addon/styles/storefront-engine.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,10 @@
.ui-combo-box .selected-list a.combo-box-option.selected:hover {
background-color: #76a9fa !important;
}

/** hotfix tag input */
.emberTagInput.form-input {
flex-wrap: wrap !important;
gap: 0.35rem !important;
height: auto !important;
}
5 changes: 4 additions & 1 deletion addon/templates/products/index/category/new.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@
<InputGroup @name="Product Description" @helpText="Enter a description of your product">
<Textarea @value={{this.product.description}} class="form-input w-full" placeholder="Enter a description of your product...." disabled={{unauthorized}} rows={{4}} />
</InputGroup>
<InputGroup @name="Product Status">
<Select class="w-full" @value={{this.product.status}} @placeholder="Select product status" @options={{this.statusOptions}} @onSelect={{fn (mut this.product.status)}} @humanize={{true}} />
</InputGroup>
<InputGroup @name="Product Tags">
<TagInput
class="form-input"
Expand Down Expand Up @@ -261,7 +264,7 @@
{{addon.description}}
</div>
<div class="col-span-2">
{{format-currency addon.price}}
{{format-currency addon.price this.product.currency}}
</div>
</div>
{{/each}}
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fleetbase/storefront-api",
"version": "0.3.17",
"version": "0.3.18",
"description": "Headless Commerce & Marketplace Extension for Fleetbase",
"keywords": [
"fleetbase-extension",
Expand Down
2 changes: 1 addition & 1 deletion extension.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Storefront",
"version": "0.3.17",
"version": "0.3.18",
"description": "Headless Commerce & Marketplace Extension for Fleetbase",
"repository": "https://github.com/fleetbase/storefront",
"license": "AGPL-3.0-or-later",
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fleetbase/storefront-engine",
"version": "0.3.17",
"version": "0.3.18",
"description": "Headless Commerce & Marketplace Extension for Fleetbase",
"fleetbase": {
"route": "storefront",
Expand Down
2 changes: 2 additions & 0 deletions server/src/Http/Controllers/ProductController.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ public function updateRecord(Request $request, string $id)
$variants = $request->array('product.variants');
$files = $request->array('product.files');

// dd($addonCategories);

// save addon categories
$product->setAddonCategories($addonCategories);

Expand Down
30 changes: 14 additions & 16 deletions server/src/Models/AddonCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

namespace Fleetbase\Storefront\Models;

use Fleetbase\Casts\Money as MoneyCast;
use Fleetbase\Models\Category;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;

class AddonCategory extends Category
Expand Down Expand Up @@ -34,29 +34,27 @@ public function setAddons(array $addons = []): AddonCategory
// get uuid if set
$id = data_get($addon, 'uuid');

// make sure the cateogry is set to this current
data_set($addon, 'category_uuid', $this->uuid);

// make sure sale price is 0 if null
if (data_get($addon, 'sale_price') === null) {
data_set($addon, 'sale_price', 0);
}
// create an upsertable array
$upsertableProductAddon = [
'category_uuid' => $this->uuid,
'name' => data_get($addon, 'name'),
'description' => data_get($addon, 'description'),
'translations' => data_get($addon, 'translations', []),
'price' => MoneyCast::apply($addon['price'] ?? 0),
'sale_price' => MoneyCast::apply($addon['sale_price'] ?? 0),
'is_on_sale' => data_get($addon, 'is_on_sale'),
];

// update product addon category
if (Str::isUuid($id)) {
ProductAddon::where('uuid', $id)->update(Arr::except($addon, ['uuid', 'created_at', 'updated_at']));
ProductAddon::where('uuid', $id)->update($upsertableProductAddon);
continue;
}

// create new product addon category
ProductAddon::create([
'category_uuid' => $this->uuid,
'name' => data_get($addon, 'name'),
'description' => data_get($addon, 'description'),
'translations' => data_get($addon, 'translations', []),
'price' => data_get($addon, 'price'),
'sale_price' => data_get($addon, 'sale_price'),
'is_on_sale' => data_get($addon, 'is_on_sale'),
...$upsertableProductAddon,
'created_by_uuid' => session('user'),
]);
}

Expand Down
19 changes: 9 additions & 10 deletions server/src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -305,23 +305,22 @@ public function setAddonCategories(array $addonCategories = []): Product
// get uuid if set
$id = data_get($addonCategory, 'uuid');

// Make sure product is set
data_set($addonCategory, 'product_uuid', $this->uuid);
$upsertableAddonCategory = [
'product_uuid' => $this->uuid,
'category_uuid' => data_get($addonCategory, 'category_uuid'),
'excluded_addons' => data_get($addonCategory, 'excluded_addons'),
'max_selectable' => data_get($addonCategory, 'max_selectable'),
'is_required' => data_get($addonCategory, 'is_required'),
];

// update product addon category
if (Str::isUuid($id)) {
ProductAddonCategory::where('uuid', $id)->update(Arr::except($addonCategory, ['uuid', 'created_at', 'updated_at', 'name', 'category']));
ProductAddonCategory::where('uuid', $id)->update($upsertableAddonCategory);
continue;
}

// create new product addon category
ProductAddonCategory::create([
'product_uuid' => $this->uuid,
'category_uuid' => data_get($addonCategory, 'category_uuid'),
'excluded_addons' => data_get($addonCategory, 'excluded_addons'),
'max_selectable' => data_get($addonCategory, 'max_selectable'),
'is_required' => data_get($addonCategory, 'is_required'),
]);
ProductAddonCategory::create($upsertableAddonCategory);
}

return $this;
Expand Down
2 changes: 2 additions & 0 deletions server/src/Models/ProductAddonCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class ProductAddonCategory extends StorefrontModel
'category_uuid',
'excluded_addons',
'max_selectable',
'is_required',
];

/**
Expand All @@ -44,6 +45,7 @@ class ProductAddonCategory extends StorefrontModel
*/
protected $casts = [
'excluded_addons' => Json::class,
'is_required' => 'boolean',
];

/**
Expand Down
Loading