Reputation: 1433
I try to create a custom field when I activate my plugin. This custom field I also find in my database but when I try to load it in my vue component the field is null. I build it like the example from shopware. I do the same as in the GitHub example, but it does not work.
PluginName.php
...
public function activate(ActivateContext $activateContext): void
{
try {
/** @var EntityRepository $repo */
$repo = $this->container->get('custom_field.repository');
// Check if custom fields already exist
$result = $repo->searchIds((new Criteria())->addFilter(new EqualsAnyFilter('name', [
self::PRODUCT_CUSTOMIZABLE,
])), $activateContext->getContext());
if ($result->getTotal() > 0) {
return;
}
/* @var EntityRepository */
$repo->create([
[
'name' => self::PRODUCT_CUSTOMIZABLE,
'type' => CustomFieldTypes::BOOL,
]
], Context::createDefaultContext());
} catch (Exception $e) {
dd($e);
}
}
My Vue component.
import template from './personal-product-canvas.html.twig';
const { mapState, mapGetters } = Shopware.Component.getComponentHelper();
Shopware.Component.register('personal-product-canvas', {
template,
data() {
return {
setPosKey: 0
};
},
computed: {
...mapState('swProductDetail', [
'product'
]),
...mapGetters('swProductDetail', [
'isLoading'
]),
isCustomizable: {
get() {
return (this.product.customFields || {}).personal_product_customizable || false;
},
set(value) {
this.$set(this.product.customFields, 'personal_product_customizable', value);
if (value) this.initializeCanvas();
}
},
},
});
Upvotes: 1
Views: 1216
Reputation: 11
I had the same problem until I noticed that I had edited the custom fields in the "German" language, but the shop was set to English. Filling out the additional fields for the English language helped me. Maybe it will help you too.
Upvotes: 1