Skip to content
Draft
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
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
"php": "^8.1",
"justbetter/statamic-glide-directive": "^3.0",
"rapidez/blade-directives": "^1.0",
"rapidez/core": "^4.0",
"rapidez/sitemap": "^4.0",
"rapidez/core": "^5.0",
"rapidez/sitemap": "^5.0",
"spatie/once": "*",
"statamic-rad-pack/runway": "^8.3",
"statamic/cms": "^5.55",
Expand Down
2 changes: 1 addition & 1 deletion config/rapidez/statamic.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// Should the data from Statamic be fetched? The entry
// data will be available as $content witin views.
'fetch' => [
// Product SKU will be matched with the "linked_product" SKU.
// Product ID will be matched with the "linked_product" ID.
'product' => true,

// Category ID will be matched with the "linked_category" ID.
Expand Down
6 changes: 4 additions & 2 deletions resources/js/components/FormConditions.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script>
import '/public/vendor/statamic/frontend/js/helpers.js'
Vue.prototype.Statamic = window.Statamic
if (window?.app?.config?.globalProperties) {
window.app.config.globalProperties.Statamic = window.Statamic
}

export default {
props: {
Expand All @@ -15,7 +17,7 @@ export default {
};
},
render() {
return this.$scopedSlots.default({
return this?.$slots?.default?.({
formData: this.formData
});
},
Expand Down
8 changes: 5 additions & 3 deletions resources/js/components/FormSubmission.vue
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
<script>
import '/public/vendor/statamic/frontend/js/helpers.js'
Vue.prototype.Statamic = window.Statamic
if (window?.app?.config?.globalProperties) {
window.app.config.globalProperties.Statamic = window.Statamic
}

export default {
props: {
Expand All @@ -15,14 +17,14 @@ export default {
};
},
render() {
return this.$scopedSlots.default({
return this?.$slots?.default?.({
submit: this.submit,
success: this.success,
error: this.error
});
},
mounted() {
let token = this.$root.csrfToken
let token = window?.app?.config?.globalProperties?.csrfToken
let csrfField = this.$el.querySelector('input[value="STATAMIC_CSRF_TOKEN"]')

if (csrfField && token && token !== 'STATAMIC_CSRF_TOKEN') {
Expand Down
14 changes: 11 additions & 3 deletions resources/js/package.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
import 'Vendor/rapidez/core/resources/js/vue'

Vue.component('form-conditions', () => import('./components/FormConditions.vue'));
Vue.component('form-submission', () => import('./components/FormSubmission.vue'));
document.addEventListener('vue:loaded', (e) => {
const vue = e.detail.vue
vue.component('form-conditions', () => import('./components/FormConditions.vue'))
vue.component('form-submission', () => import('./components/FormSubmission.vue'))
})

document.addEventListener('statamic:nocache.replaced', (e) => {
window.app.csrfToken = e?.detail?.csrf ?? window.app.csrfToken
const token = e?.detail?.csrf
if (token) {
if (window?.app?.config?.globalProperties) {
window.app.config.globalProperties.csrfToken = token
}
}
})
4 changes: 1 addition & 3 deletions src/Collections/Brands.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace Rapidez\Statamic\Collections;

use Statamic\Facades\Site;

class Brands extends Base
{
protected string $handle = 'brands';
Expand Down Expand Up @@ -36,4 +34,4 @@ public function visible(): bool
{
return false;
}
}
}
24 changes: 13 additions & 11 deletions src/Commands/InvalidateCacheCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -75,20 +75,22 @@ public function handle(Cacher $cacher, Writer $writer): void

protected function addProductsUrls(): self
{
$products = config('rapidez.models.product')::withoutGlobalScopes()
$productIds = config('rapidez.models.product')::query()
->where('updated_at', '>=', $this->latestCheck)
->orWhereIn('entity_id', $this->getUpdatedStockProducts())
->with(['parent:entity_id' => ['rewrites']])
->with('rewrites')
->get('entity_id');
->pluck('entity_id');

foreach ($products as $product) {
$this->addUrls($this->getUrlsFromRewrites($product->rewrites));
$parentIds = config('rapidez.models.product_super_link')::whereIn('product_id', $productIds)
->groupBy('parent_id')
->pluck('parent_id');

if ($product->parent) {
$this->addUrls($this->getUrlsFromRewrites($product->parent->rewrites));
}
}
$allIds = $productIds->merge($parentIds)->unique();

$rewrites = config('rapidez.models.rewrite')::whereIn('entity_id', $allIds)
->where('entity_type', 'product')
->pluck('request_path');

$this->addUrls($rewrites);

return $this;
}
Expand Down Expand Up @@ -116,7 +118,7 @@ protected function getUpdatedStockProducts()

protected function addCategoryUrls(): self
{
$categories = config('rapidez.models.category')::withoutGlobalScopes()
$categories = config('rapidez.models.category')::query()
->where('updated_at', '>=', $this->latestCheck)
->get('entity_id');

Expand Down
13 changes: 3 additions & 10 deletions src/Models/Category.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,18 @@
namespace Rapidez\Statamic\Models;

use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Rapidez\Core\Models\Category as CoreCategory;
use StatamicRadPack\Runway\Traits\HasRunwayResource;
use Illuminate\Database\Eloquent\Model;
use Rapidez\Statamic\Models\Traits\HasContentEntry;
use Rapidez\Statamic\Observers\RunwayObserver;
use Rapidez\Statamic\Facades\RapidezStatamic;

#[ObservedBy([RunwayObserver::class])]
class Category extends Model
class Category extends CoreCategory
{
use HasRunwayResource, HasContentEntry;

protected $primaryKey = 'entity_id';
protected $with = ['entry'];

public string $linkField = 'linked_category';
public string $collection = 'categories';

public function getTable()
{
return 'catalog_category_flat_store_'.RapidezStatamic::getCurrentStoreId();
}
public string $collection = 'categories';
}
24 changes: 12 additions & 12 deletions src/Models/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,36 +4,36 @@

use Illuminate\Database\Eloquent\Attributes\ObservedBy;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
use Rapidez\Statamic\Collections\Products;
use Rapidez\Core\Models\Product as CoreProduct;
use Rapidez\Statamic\Models\Traits\HasContentEntry;
use Rapidez\Statamic\Observers\RunwayObserver;
use StatamicRadPack\Runway\Traits\HasRunwayResource;
use Statamic\Facades\Site;
use Statamic\Statamic;
use Rapidez\Statamic\Facades\RapidezStatamic;

#[ObservedBy([RunwayObserver::class])]
class Product extends Model
class Product extends CoreProduct
{
use HasRunwayResource, HasContentEntry;

protected $primaryKey = 'sku';
protected $keyType = 'string';
protected $with = ['entry'];

public string $linkField = 'linked_product';
public string $linkKey = 'sku';
public string $collection = 'products';

protected function getAttributeRelationKey(): string
{
return 'entity_id';
}

protected static function booting()
{
parent::booting();

static::addGlobalScope(function (Builder $builder) {
$builder->whereIn('visibility', config('rapidez.statamic.runway.product_visibility'));
$builder->whereInAttribute('visibility', config('rapidez.statamic.runway.product_visibility'));
});
}

public function getTable()
{
return 'catalog_product_flat_' . RapidezStatamic::getCurrentStoreId();
static::addGlobalScope(fn ($builder) => $builder->with('entry'));
}
}
3 changes: 3 additions & 0 deletions src/Observers/RunwayObserver.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public function retrieved(Model $model)
->keys()
->toArray();

// TODO: SKU seems to get filtered out here by default, as it doesn't seem to have the read_only visibility?
// Make sure SKU never gets filtered because otherwise we can't generate URLs in runway.

// Exclude the potential duplicated keys
// Ignore the Magento values in that case
$filteredAttributes = Arr::except(
Expand Down