I'm trying to create a custom-field that is an entity-single-select for customers, exactly like the one in the sw-order module as seen here
sw-order-create-details-header > sw-entity-single-select
Is there some way for me, to configure the look of my custom-field to be the same as the extended select-field in the sw-order module?
With that i mean, inclusive of firstName, lastName, address and customernumber?
(Without creating a a new component)
What i have so far is this:
protected $customFields = [
[
'name' => 'referrer_set',
'config' => [
'label' => [
'en-GB' => 'Referrer',
'de-DE' => 'Referrer',
],
],
'customFields' => [
[
'active' => true,
'name' => 'refferer_set',
'type' => CustomFieldTypes::ENTITY,
'config' => [
'componentName' => 'sw-entity-single-select',
'entity' => CustomerDefinition::ENTITY_NAME,
'placeholder' => "Wurde empfohlen von ...",
'highlightSearchTerm' => true,
'allowEntityCreation' => false,
'show-clearable-button' => true,
'labelProperty' => 'firstName',
'label' => [
'en-GB' => 'Empfohlen von',
'de-DE' => 'Empfohlen von',
],
],
],
],
'relations' => [
[
'entityName' => CustomerDefinition::ENTITY_NAME,
],
],
],
];
Unfortunately this isn't quite so trivial to achieve.
You could override the component which is responsible for rendering custom fields sw-form-field-renderer.
Inside the override you check if it is your specific custom field that should be rendered. In the template of the override you then set the content of the slot result-item, which is a corresponding to each option in the dropdown. You'll additionally have to extend the binds of the component with a criteria to add the billing address of the customer as an association.
The override:
import template from './sw-form-field-renderer.html.twig';
const { Component } = Shopware;
const { Criteria } = Shopware.Data;
Component.override('sw-form-field-renderer', {
template,
computed: {
isMyCustomField() {
return this.config.componentName === 'sw-entity-single-select' && this.$attrs.name === 'refferer_set';
},
bind() {
const bind = this.$super('bind');
if (this.isMyCustomField) {
const criteria = new Criteria;
criteria.addAssociation('defaultBillingAddress.country');
bind.criteria = criteria;
}
return bind;
},
},
});
The template sw-form-field-renderer.html.twig:
{% block sw_form_field_renderer_scope_slots %}
{% parent %}
<template
v-if="isMyCustomField"
#result-item="{ item, index, labelProperty, searchTerm, highlightSearchTerm, isSelected, setValue, getKey }"
>
<!-- copy/paste from sw-order-create-details-header -->
<li
is="sw-select-result"
:selected="isSelected(item)"
v-bind="{ item, index }"
class="sw-order-create-details-header__customer-result"
#item-select="setValue"
>
<div class="sw-order-create-details-header__customer-result-item has-many-childrens">
<div>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'firstName') || getKey(item, `translated.firstName`)"
:search-term="searchTerm"
/>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'lastName') || getKey(item, `translated.lastName`)"
:search-term="searchTerm"
/>
</div>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'customerNumber') || getKey(item, `translated.customerNumber`)"
:search-term="searchTerm"
class="text-truncate"
/>
</div>
<div
v-if="getKey(item, 'company') || getKey(item, `translated.company`)"
class="sw-order-create-details-header__customer-result-item"
>
<sw-highlight-text
v-if="highlightSearchTerm"
:text="getKey(item, 'company') || getKey(item, `translated.company`)"
:search-term="searchTerm"
/>
</div>
<div class="sw-order-create-details-header__customer-result-item text-gray-500">
{{ item.defaultBillingAddress.street }} <br>
{{ item.defaultBillingAddress.zipcode }} {{ item.defaultBillingAddress.city }} <br>
{{ item.defaultBillingAddress.country.name }}
</div>
</li>
</template>
{% endblock %}
Related
I made a request to my backend and brought all the categories to the homepage. From there I redirected to a page called [category_slug].jsx.
I'm getting data with useEffect and I'm pulling it from the context api
categories.map((category) => (
<Link
href={{ pathname: `/categories/${category.category_slug}`, query: category }}
className="text-sm hover:underline hover:opacity-60"
key={category.id}
>
{category.name}
</Link>
))
Also, I used this method before to make the page with the videos and it worked then.
All data comes to that page, but the videos come with 2 empty strings, but it should not come as such.
{
"id": "9",
"name": "test2",
"category_slug": "test2",
"description": "testt2",
"videos": [
"",
""
],
"image": "",
"created": "2022-12-07T02:07:05.838815Z",
"updated": "2022-12-07T02:07:05.838840Z"
}
My [id] page:
import React from "react";
const CategoryPage = () => {
const router = useRouter()
const category = router.query;
console.log(category)
// captilaze first letter and lowercase the rest
const capitalize = (s) => {
if (typeof s !== "string") return "";
return s.charAt(0).toUpperCase() + s.slice(1).toLowerCase();
};
return (
<>
{ /* <CustomHead title={capitalize(category.name)} />*/}
<div className="my-10 mx-auto flex min-h-screen px-24 py-10 ">
<div className="flex w-full flex-col bg-white p-10">
{ /* <h1 className="text-2xl font-bold up capitalize">{category.name}</h1>*/}
<div className="mt-10 grid grid-cols-1 place-items-center gap-2 md:grid-cols-3">
</div>
</div>
</div>
</>
);
};
export default CategoryPage;
Please excuse me if I didn't express myself very well.
I am trying to display member and company using MUI Autocomplete.
I have suggestion array to show as options
[
{
"__typename": "Member",
"id": "ckwa91sfy0sd241b4l8rekas9jx",
"name": "my name 2",
"companyName": ""
},
{
"__typename": "Member",
"id": "ckwac4ijl25dsd80b4l8fpsrc64o",
"name": "my name",
"companyName": ""
},
{
"__typename": "Member",
"id": "ckwa8z6z7004dsd2b4l81m6ras9c",
"name": "my name 1",
"companyName": "A COMPANY"
}
]
I use this to display
<Autocomplete
id="free-solo-demo"
freeSolo
options={
suggestion &&
suggestion.map(
(suggestion: any) =>
suggestion.name
)
}
onChange={(event, value) =>
HandleUserProfile(value)
}
renderInput={(params) => (
<TextField
{...params}
placeholder="Search..."
onChange={handleChange}
/>
)}
/>
By using this I am getting options if only I search with member name.
I want to search with both company and member and need to customize UI of option.
I tried this
<Autocomplete
id="free-solo-demo"
freeSolo
options={suggestion}
getOptionLabel={(option) => `${option.name} ${option.companyName}`}
renderOption={(option)=>{
return <h1>{`${option.name}: ${option.companyName}`}</h1>
}}
onChange={(event, value) =>
HandleUserProfile(value)
}
renderInput={(params) => (
<TextField
{...params}
placeholder="Search..."
onChange={handleChange}
/>
)}
/>
but It is not working.
it shows error TypeScript error in ... Property 'name' does not exist on type 'never'. TS2339
First, you should make sure the name field doesn't have any duplicated values, that's why you should use the mandatory id field to select one.
And also you need to build a custom filter function or use createFilterOptions hook from Autocomplete component.
https://mui.com/components/autocomplete/#custom-filter
import Autocomplete, { createFilterOptions } from '#mui/material/Autocomplete';
...
const filterOptions = createFilterOptions({
stringify: ({ name, companyName }) => `${name} ${companyName}`
});
<Autocomplete
options={suggestion}
getOptionLabel={option => option.name}
filterOptions={filterOptions}
...
/>;
I wrote my own wishlist in python3 flask (with apache mod_wsgi)
this is my data structure for the wishlist items:
{
},
"": {
"images": {
"pic": ""
},
"buylinks": {
"": {
"link": "",
"price": ""
}
},
"want": "",
"comments": ""
}
}
for example:
"Nintendo Joy-Con (L/R) - Gray": {
"images": {
"pic": "wishlist/joycons-grey.jpg"
},
"buylinks": {
"Amazon": {
"link": "https://www.amazon.com/dp/B01N6QKT7H",
"price": "66.99"
}
},
"want": "7/10",
"comments": "extra joycons for playing with friends on my switch"
},
right now every time I update the json file containing the wishlist data the apache server jinja template spits it iut in a different order
my jinja template looks like
<table>
<tr>
<th>Name</th>
<th>Image(s)</th>
<th>Links To Buy</th>
<th>Want/10</th>
<th>Comments</th>
</tr>
{% for key in wishlist.keys() %}
<tr>
<td><b>{{ key }}</b></td>
<td>{% for image in wishlist[key]["images"].keys() %}
<img src="{{ url_for('static', filename=wishlist[key]["images"][image]) }}" width="250px">
{% endfor %}</td>
<td>{% for merchant in wishlist[key]["buylinks"].keys() %}
{{ merchant}} (~${{ wishlist[key]["buylinks"][merchant]["price"] }})
<br>{% endfor %}</td>
<td><a> {{ wishlist[key]["want"] }} </a></td>
<td> {{ wishlist[key]["comments"] }}</td>
</tr>
{% endfor %}
</table>
how do I modify the {% for key in wishlist.keys() %} line to sort the wishlist by the value of the want key such that 10/10 is at the beginning and 0/10 is at the end? (the value to use to sort the example item would be "7/10")
I think I need to use the "sorted" function but I'm not sure how to
so to get this to work I had to add
wishlist_keys = sorted(wishlist.keys(), reverse=True, key=lambda x: wishlist[x]["want"] )
to my flask python code and pass wishlist_keys into render_template()
and change the template to
{% for key in wishlist_keys %}
I need the title to show the (current date - 1)
When I hard code a value eg "17"
This is where the component is displaying (in index)
{% include 'home/key-facts' with {
content: {
keyFactsHeading: entry.keyFactsHeading,
keyFacts: entry.keyFacts,
keyFactsSmall: entry.keyFactsSmall,
}
Which is this file here --->
This is how I've included the date
{% include '_components/bg-type' with {
content: {
title: {{ "now"|date('Y') - 1 }}
},
} only %}
I am passing content.title into here --->
<div class="bg-type">
<div class="bg-type__text bg-type--large">
{{ content.title }}
</div>
</div>
When hardcoding the value as below it works fine but when I add
title: {{ "now"|date('Y') - 1}} I get a 500 error.
{% include '_components/bg-type' with {
content: {
title: 17
},
} only %}
Why is this? Can you also explain why what I'm trying doesn't work?
I've tried dumping {{ "now"|date('Y') - 1}} and I can see the year I want
The {{ ... }} notation is used to output data. In this case you only want to pass data towards an include. Notice you already inside a twig-statement, {% include .... %}
The correct syntax would be
{% include '_components/bg-type' with {
content: {
title: "now"|date('Y') - 1,
},
} only %}
i have user object that contain all user fields.
and listFields array that have ["user.id", "user.email","user.gender"].
so variables in string.
i want to loop listFields and print it's original value from user object
currently user.id user.email print on screen.
i want to print it's value in screen.
have any solution for this! or it is possible?
Mycode
{% for fieldName in listFields %}
<td>
{{ fieldName }}
</td>
{% endfor %}
If you want to print dynamic variables u can make use of the function attribute:
{% set user_fields = [ 'user.id', 'user.email', 'user.gender', 'alice.email', 'bob.id', 'bob.foo', ] %}
{% for field in user_fields %}
{{ attribute(attribute(_context, (field|split('.'))[0])|default([]), (field|split('.'))[1])|default(null) }}
{% endfor %}
demo
array:3 [▼
"user" => array:3 [▼
"id" => 42
"email" => "user#example.com"
"gender" => 0
]
"bob" => array:3 [▼
"id" => 1
"email" => "bob#example.com"
"gender" => 0
]
"alice" => array:3 [▼
"id" => 100
"email" => "alice#example.com"
"gender" => 1
]
]