Spartacus storefront feature disabling is not working - spartacus-storefront

We have problems with features disabling. When we use approach from documentation and disabling saveForLater feature features: {saveForLater: false} it means that SelectiveCart service should not be working, or I'm wrong here? Is there a proper way how to disable this service/feature? We need to avoid additional calls which spartacus makes with url: selectivecart${activeBaseSite}${this.customerId}

This feature flag does not affect the SelectiveCartService in any way. I guess this is intended behavior as you might want to use this service somewhere else. This flag only affects the UI - e.g. it prevents from rendering the "Save for later" button.
I presume that you're using the demo instance or Spartacus sample data. This sample data contains a SaveForLaterComponent in the TopContent slot on a cart page.
{
"slotId" : "TopContent-cartPage",
"slotUuid" : "eyJpdGVtSWQiOiJUb3BDb250ZW50LWNhcnRQYWdlIiwiY2F0YWxvZ0lkIjoiZWxlY3Ryb25pY3Mtc3BhQ29udGVudENhdGFsb2ciLCJjYXRhbG9nVmVyc2lvbiI6Ik9ubGluZSJ9",
"position" : "TopContent",
"name" : "Top Slot for Cart Page",
"slotShared" : false,
"components" : {
"component" : [ {
"uid" : "CartComponent",
"uuid" : "eyJpdGVtSWQiOiJDYXJ0Q29tcG9uZW50IiwiY2F0YWxvZ0lkIjoiZWxlY3Ryb25pY3Mtc3BhQ29udGVudENhdGFsb2ciLCJjYXRhbG9nVmVyc2lvbiI6Ik9ubGluZSJ9",
"typeCode" : "CMSFlexComponent",
"modifiedTime" : "2020-04-23T21:36:55.684Z",
"name" : "Cart Display Component",
"container" : "false",
"flexType" : "CartComponent"
}, {
"uid" : "SaveForLaterComponent",
"uuid" : "eyJpdGVtSWQiOiJTYXZlRm9yTGF0ZXJDb21wb25lbnQiLCJjYXRhbG9nSWQiOiJlbGVjdHJvbmljcy1zcGFDb250ZW50Q2F0YWxvZyIsImNhdGFsb2dWZXJzaW9uIjoiT25saW5lIn0=",
"typeCode" : "CMSFlexComponent",
"modifiedTime" : "2020-04-23T21:36:55.717Z",
"name" : "SaveForLater Component",
"container" : "false",
"flexType" : "SaveForLaterComponent"
} ]
}
This configuration makes Spartacus render the SaveForLaterComponent which calls the SelectiveCartService. The component itself doesn't check the feature flags.
So the simple solution is to remove this component from the cart page in the CMS.
I hope this helps ;)

Related

How do I get Watch Mode with Sanity.io and Gatsby to refresh content when referenced documents are edited in the CMS / Studio?

I'm using Sanity.io, GatsbyJS 3.x
Watch mode works great when you update content in the CMS, except for when the content you edit is part of a referenced schema of type 'document'.
Put another way, changes made to a document referenced by another document will not re-render the page despite having watch mode on and configured properly.
For example, here is a snippet from my Page schema.
...
{
name: "content",
type: "array",
title: "Page Sections",
description: "Add, edit, and reorder sections",
of: [
{
type: 'reference',
to: [
{ type: 'nav' },
{ type: 'section' },
{ type: 'footer' }
]
}
],
},
...
The above schema references a
nav schema
section schema
footer schema
Each of these are type 'document'.
See the example below.
export default {
type: 'document',
name: 'section',
title: 'Page Sections',
fields: [
{
name: 'meta',
title: 'Section Meta Data',
type: 'meta'
},
...
I want to reference a document, rather than an object, because I need to use the content created based on these schemas to be re-used in throughout the application.
Finally, I've configured the source plugin correctly for watch mode.
Gatsby Config is set properly
{
resolve: `gatsby-source-sanity`,
options: {
projectId: `asdfasdf`,
dataset: `template`,
watchMode: true,
overlayDrafts: true,
token: process.env.MY_SANITY_TOKEN,
},
},
In the CMS / Studio, when you edit one of the fields, you can see Gatsby re-compile in dev mode from the terminal. However, the page does not auto reload and display the changes made to the referenced document.
I've tried reloading the page with the reload button and via hard refresh, the changes do not render.
The only way to render the changes is to go back to the CMS and edit a field on the main “Page” document. Then it refreshes immediately.
Am I doing something wrong? Is this expected behavior? Is there a way to get this to work?
For those that run across this issue, I was able to answer my own question. I hope this saves you the day's it took me to find a solution.
Solution TLDR
You need to explicitly query the referenced document in order for watch mode to work properly.
Details with Examples
Summary
The gatsby-source-sanity plugin provides convenience queries that start with _raw for array types. When you use the _raw query in your GraphQL query, it will not trigger watch mode to reload the data. You need to explicitly query the referenced document in order for watch mode to work properly. This may have to do with how the plugin sets up listeners and I don't know if this is a bug or a feature.
Example
My Page Document has the following schema
{
name: "content",
type: "array",
title: "Page Sections",
description: "Add, edit, and reorder sections",
of: [
{
type: "reference",
to: [
{ type: "nav" },
{ type: 'section' },
],
},
],
},
The section is a reference to a section document.
{ type: 'section' }
The reason I'm not using an object is because I want the page sections to be re-usable on multiple pages.
Assuming you have watch mode enabled properly in your gatsby-config.js file, watch mode, like so...
// gatsby-config.js
{
resolve: `gatsby-source-sanity`,
options: {
projectId: `asdf123sg`,
dataset: `datasetname`,
watchMode: true,
overlayDrafts: true,
token: process.env.SANITY_TOKEN,
},
},
Then you should see the following behavior:
listen for document/content updates
re-run queries, update the data, hot-reload the page
You'll see the following scroll in your terminal window.
success Re-building development bundle - 1.371s
success building schema - 0.420s
success createPages - 0.020s
info Total nodes: 64, SitePage nodes: 9 (use --verbose for breakdown)
success Checking for changed pages - 0.001s
success update schema - 0.081s
success onPreExtractQueries - 0.006s
success extract queries from components - 0.223s
success write out requires - 0.002s
success run page queries - 0.010s - 1/1 99.82/s
This works great if you are querying the main document or any referenced objects. However, if you are querying any references to another document then there is one gotcha you need to be aware of.
The Gotcha
When you use the _raw query in your GraphQL query, it will not trigger watch mode to reload the data. You need to explicitly query the referenced document in order for watch mode to work properly.
Example: This Query will NOT work
export const PageQuery = graphql`
fragment PageInfo on SanityPage {
_id
_key
_updatedAt
_rawContent(resolveReferences: {maxDepth: 10})
}
`
Example: This query WILL Work
export const PageQuery = graphql`
fragment PageInfo on SanityPage {
_id
_key
_updatedAt
_rawContent(resolveReferences: {maxDepth: 10})
content {
... on SanitySection {
id
}
}
}
`
This additional query is the key
Here is where I am explicitly querying the document that is being referenced in the 'content' array.
content {
... on SanitySection {
id
}
}
You don't actually need to use the data that results from that query, you simply need to include this in your query.
My guess is that this informs the gatsby-source-sanity plugin to set up a listener, whereas the _rawContent fragment does not.
Not sure if this is a feature, bug, or just expected behavior. At the time of writing the versions were as follows.
"gatsby": "3.5.1",
"gatsby-source-sanity": "^7.0.0",

TYPO3 10.4 new fields not found in frontend

I have extended database table fe_users with new field using extension builder. The fields are visible in backend user-interface, but not available in frontend in Typo3 10.4.x . But the same code works fine in Typo3 9.x frontend and backend.
I have also tried setting recordType to nothing in the ext_typoscript_setup.typoscript but this also does not help
mapping {
tableName = fe_users
recordType =
}
Any ideas on what more to look for?
The table mapping of the Extbase persistence is not longer possible in TypoScript. Migrate your TypoScript to a PHP file named EXT:myextension/Configuration/Extbase/Persistence/Classes.php.
See breaking change 87623 for further details.
A typical Classes.php file looks like the following.
<?php
return [
\Vendor\Extension\Domain\Model\Object::class => [
'tableName' => 'tx_extension_domain_model_object',
]
];
This is how I implemented it. There was one more line (.i.e 'subclasses') that had to be added to Michael's response. (This is tested in Typo3 11.x as well)
My Configuration/Extbase/Persistence/Classes.php
<?php
declare(strict_types=1);
return [
\TYPO3\CMS\Extbase\Domain\Model\FrontendUser::class => [
'subclasses' => [
'\T3IN\T3inStores\Domain\Model\UserStore' => \T3IN\T3inStores\Domain\Model\UserStore::class,
]
],
\T3IN\T3inStores\Domain\Model\UserStore::class => [
'tableName' => 'fe_users',
'recordType' => 'Tx_T3inStores_UserStore',
],
];
Ref
For every superclass additional all subclasses have to be declared under subclasses
recordType : Look up the TCA of the model to get this value. Or lookup DB after creating a record of that type.

BigCommerce Stencil Custom Page template not appearing

In Page Builder I've added a page called About Us which has the url '/about-us/'
I've been following the instructions found here
https://developer.bigcommerce.com/stencil-docs/storefront-customization/custom-templates
in order to make a custom template for that page.
I made a file called about-us.html in templates/pages/custom/page with the contents:
<h1>About Us Page Test</h1>
My .stencil file looks like the following
{
"normalStoreUrl": "my url",
"accessToken": "my access token",
"port": "3003",
"customLayouts": {
"brand": {},
"category": {},
"page": {
"about-us.html": "/about-us/"
},
"product": {}
}
}
I've stopped and reran 'stencil start' but every time I visit localhost:3003/about-us/ it just shows the normal page instead of the custom template I build.
Is there something I'm missing? Is this an issue with using the page builder in combination with stencil?
I assume you haven't set the custom template for your page yet.
Go to Web Pages and edit your About Us page then look for the Template Layout File dropdown. Your custom template should appear there if it is setup correctly.
The issue was resolved when a full system reboot was performed. I'm not sure why stopping and restarting stencil did not resolve this.

Is there anyway to use JSON-LD Schema not inlined

Is there anyway to use JSON-LD without including the script inline in the HTML, but still get Google (& other) spiders to find it? Looking around I've seen some conflicting information.
If this was the JSON-LD file:
<script type="application/ld+json">
{
"#context" : "http://schema.org",
"#type" : "WebSite",
"name" : "Example Site",
"alternateName" : "example",
"description" : "Welcome to this WebSite",
"headline" : "Welcome to Website",
"logo" : "https://example.com/public/images/logo.png",
"url" : "https://example.com/"
}
</script>
And I have this in the head of the HTML:
<script src="/public/json-ld.json" type="application/ld+json"></script>
EDIT: I've also tried:
<link href="/public/json-ld.json" rel="alternate" type="application/ld+" />
Google Spiders seem to miss it and so does the testing tool unless I point it directly at the file. I'm trying to work around unsafe-inline in the CSP. And the only thing I can find is this, which would work in Chrome but don't want to be firing console errors on every other browser. Plus, I just like the idea of Schema.org data being abstracted out of the page structure. Would adding the JSON-LD to the sitemap for Google Webmaster Tools help?
Apologies, total noob to JSON-lD and keep ending up in email documentation (this would be for a site) or old documentation.
True, it can not be made external and it is not supported inline, but you can still achieve what you want by injecting it into the DOM via a JavaScript file.
Note: I am using an array for neatness so I can segment all the structured data elements and add an infinite amount of them. I have a more complicated version of this code on my websites and actually have an external server side rendered file masquerading as a JavaScript file.
An yes Google search bot does understand it. May take days for it to register and using Webmaster tools to force a re-crawl does not seem to force a refresh of JSON-LD data - seems like you just have to wait.
var structuredData = {
schema: {
corporation: {
'#context': 'http://schema.org',
'#type': 'Corporation',
'name': 'Acme',
'url': 'https://acme.com',
'contactPoint':
{
'#type': 'ContactPoint',
'telephone': '+1-1234-567-890',
'contactType': 'customer service',
'areaServed': 'US'
}
},
service: {
'#context': 'http://schema.org/',
'#type': 'Service',
'name': 'Code optimization',
'serviceOutput' : 'Externalized json',
'description': 'Inline json to externalized json'
},
},
init: function () {
var g = [];
var sd = structuredData;
g.push(sd.schema.corporation);
g.push(sd.schema.service);
//etc.
var o = document.createElement('script');
o.type = 'application/ld+json';
o.innerHTML = JSON.stringify(g);
var d = document; (d.head || d.body).appendChild(o);
}
}
structuredData.init();

Using HATEOAS with JQuery datatables

Having a HTTP rest like API that is rendering HAL responses (like spring-data-rest) i am searching for the best way to integrate an angular client that is using jquery datatables.
Is there any way to do this without lot of work?
I've been searching without success about this topic even when both datatables and spring-data-rest are very popular.
This is a 2 years old question, but here is how to do it:
$(document).ready(function() {
/* Init the files table */
var filesTable = $("#tags").DataTable({
"processing": true,
"ajax": {
"url": "/api/v2/tag/search/findCategoryTags",
"dataSrc": "_embedded.tags"
},
"columns": [
{ "data": "name" },
{ "data": "id" }
]
});
});
Use the dataSrc property for the Ajax. More info here.
One of the problems here is that you need to deal with the incompatibility of the pagination and sorting scheme on the spring-data-rest (HAL) and Datatables. Take a look at the function datatable2Rest (...) in this link:
https://github.com/gcase/spring-data-rest-datatable-example/blob/master/spring-data-rest-datatables.md