I want to create a new customer group in a plugin. The name of this customer group should be translatable. How can I achieve this? Here is my code until now:
$customerGroupRepository->create([
[
'id' => Uuid::randomHex(),
'registrationActive' => false,
'displayGross' => true,
'translations' => [
Defaults::LANGUAGE_SYSTEM => [
'name' => 'Customer group',
],
'de_DE' => [
'name' => 'Kundengruppe',
],
'en_GB' => [
'name' => 'Customer group',
]
]
],
], $context);
But this doesn't work. The name of the customer group is allways 'Customer group' no matter which language I choose in the shopware backend.
The locales need to include hyphens: de-DE, en-GB
Using the correct locale they should be resolved to a language.id.
Generally speaking it wouldn't be a bad idea though to first fetch the id of the language entities and then use them as the key instead. Just as a precaution to make sure the language/locale exists.
With language.id:
[
// ...
'translations' => [
Defaults::LANGUAGE_SYSTEM => [
'name' => 'Customer group',
],
'9e4f6342174749aa897c5b64d57d7996' => [
'name' => 'Kundengruppe',
],
'0a7f24f26e48436d9f3b343fc43b65b7' => [
'name' => 'Customer group',
]
]
]
With locale:
[
// ...
'translations' => [
Defaults::LANGUAGE_SYSTEM => [
'name' => 'Customer group',
],
'de-DE' => [
'name' => 'Kundengruppe',
],
'en-GB' => [
'name' => 'Customer group',
]
]
]
Should both work.
Related
Is there a way to simultaneously update a customField and all of its translations?
Right now the code looks like this (from a cli command)
$context = Context::createDefaultContext();
$data = [[
'id' => $productId,
'customFields' => [
'product_is_new' => true
]
]];
$this->productRepository->update($data, $context);
This only updates the custom field in the main language, I suppose this is because of the default context. What is the way to go to update the customField and all of its translations?
You need to provide CustomFields for each language. E.G.
$data = [
'id' => $productId,
'translations' => [
'languageId1' => [
'customFields' => [
'product_is_new' => true
]
],
'languageId2' => [
'customFields' => [
'product_is_new' => true
]
],
]
];
$this->productRepository->update($data, $context);
I'm trying to figure out how to store metadata directly into a Stripe CC payments subscription. I'm using the PHP SDK and have:
$test = $stripe->checkout->sessions->create([
'customer_email' => $_GET["who"],
'success_url' => $success_url,
'payment_method_types' => ['card'],
'cancel_url' => "https://www.example.com",
'line_items' => [
[
'price' => $price_plan_id,
'quantity' => 1,
],
],
'payment_intent_data' => [
'metadata' => [
'who' => $_GET["who"],
'total' => $_GET["total"],
'period' => $_GET["period"],
'description' => $_GET["description"],
'district' => $_GET["district"],
'what' => $_GET["what"],
'ip' => $_SERVER["REMOTE_ADDR"]
]
],
'mode' => $mode 'subscription',
]);
This gives me an error:
You can not pass payment_intent_data in subscription mode.
I've tried just doing:
$test = $stripe->checkout->sessions->create([
'customer_email' => $_GET["who"],
'success_url' => $success_url,
'payment_method_types' => ['card'],
'cancel_url' => "https://www.example.com",
'line_items' => [
[
'price' => $price_plan_id,
'quantity' => 1,
],
],
'metadata' => [
'who' => $_GET["who"],
'total' => $_GET["total"],
'period' => $_GET["period"],
'description' => $_GET["description"],
'district' => $_GET["district"],
'what' => $_GET["what"],
'ip' => $_SERVER["REMOTE_ADDR"]
],
'mode' => $mode 'subscription',
]);
And while it kind of works, its not assigned to the subscription (when you view it metadata is empty)
How do I go passing this along? I want to keep this data stored in the subscription element (not just the payment)
Thanks
You want to pass the metadata on to the resulting Subscription object by setting it in subscription_data.metadata: https://stripe.com/docs/api/checkout/sessions/create#create_checkout_session-subscription_data-metadata
How get i sort my rows by field i get from model getter like this
* Returns the score for this team
*/
public function getScore() {
$score = 0;
if (!empty($this->bonus_points)) {
$score += $this->bonus_points;
}
foreach (Attempt::find()->where(['team_id' => $this->id, 'marked' => 1])->all() as $attempt) {
$score -= $attempt->cost;
$score += $attempt->reward;
}
return $score;
}
View Code
GridView::widget([
'id' => 'quickfire-grid',
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'filterPosition' => GridView::FILTER_POS_HEADER,
'tableOptions' => [
'class' => 'table'
],
'layout' => "{summary}\n{items}\n{pager}",
'columns' => [
['class' => 'yii\grid\CheckboxColumn'],
'name',
[
'attribute' => 'bonus_points',
'label' => 'Adjustment',
'filter' => false
],
[
'attribute' => 'score',
'label' => 'Score',
'filter' => false,
],
[
'label' => 'Adjust score',
'format' => 'raw',
'value' => function ($data) use ($game) {
return Html::input('text', 'score-' . $data->id, '0', ['id' => 'score-' . $data->id]) . ' ' . Html::a('Adjust score', '#', ['class' => 'btn btn-danger btn-adjust-score', 'data-team-id' => $data->id, 'data-href' => Url::toRoute(['adjust-scores', 'game_id' => $game->id, 'skipConfirmation' => true])]);
},
],
],
]);
Is it possible to sort grid by score field ? I think need to add some javascript code. I have read this article but there is no solution https://www.yiiframework.com/wiki/621/filter-sort-by-calculatedrelated-fields-in-gridview-yii-2-0.
Team::find()->select(['total_score' => 'ifnull(s.score, 0)+team.bonus_points'])
->leftJoin([
's' => Attempt::find()
->select('team_id, SUM(reward-cost) as score')
->where(['marked' => 1])
->groupBy('team_id')
], 's.team_id=team.id')
->orderBy('total_score')
Something like this) Modify select with your needs...
I am working with Shopware API. I have wrote code to update value from csv to shopware using api. My sample content is shows below.
$configurationSet = [
'name' => "Test set",
'type' => 2,
'groups' => [
[
'name' => 'Farbe',
'options' => [
"name" => "Red"
]
],
[
'name' => 'Größe',
'options' => [
'name' => 'XXL',
]
]
]
];
$variant['configuratorOptions'] = [
['group' => 'Farbe', 'option' => 'Red'],
['group' => 'Größe', 'option' => 'XXL']
];
When I update data values are saving. But size shows images over it. How can I fix this by api? What am I missing? Thanks in advance.
Please see the screen shot.
I need some help with Logstash. I currently have the below Logstash config which works. When the [message] tag has "Token validation failed" in it it sends an email out saying auth issue.
input {
tcp {
codec => "json"
port => 5144
tags => ["windows","nxlog"]
type => "nxlog-json"
}
} # end input
filter {
if [type] == "nxlog-json" {
date {
match => ["[EventTime]", "YYYY-MM-dd HH:mm:ss"]
timezone => "Europe/London"
}
mutate {
rename => [ "AccountName", "user" ]
rename => [ "AccountType", "[eventlog][account_type]" ]
rename => [ "ActivityId", "[eventlog][activity_id]" ]
rename => [ "Address", "ip6" ]
rename => [ "ApplicationPath", "[eventlog][application_path]" ]
rename => [ "AuthenticationPackageName", "[eventlog][authentication_package_name]" ]
rename => [ "Category", "[eventlog][category]" ]
rename => [ "Channel", "[eventlog][channel]" ]
rename => [ "Domain", "domain" ]
rename => [ "EventID", "[eventlog][event_id]" ]
rename => [ "EventType", "[eventlog][event_type]" ]
rename => [ "File", "[eventlog][file_path]" ]
rename => [ "Guid", "[eventlog][guid]" ]
rename => [ "Hostname", "hostname" ]
rename => [ "Interface", "[eventlog][interface]" ]
rename => [ "InterfaceGuid", "[eventlog][interface_guid]" ]
rename => [ "InterfaceName", "[eventlog][interface_name]" ]
rename => [ "IpAddress", "ip" ]
rename => [ "IpPort", "port" ]
rename => [ "Key", "[eventlog][key]" ]
rename => [ "LogonGuid", "[eventlog][logon_guid]" ]
rename => [ "Message", "message" ]
rename => [ "ModifyingUser", "[eventlog][modifying_user]" ]
rename => [ "NewProfile", "[eventlog][new_profile]" ]
rename => [ "OldProfile", "[eventlog][old_profile]" ]
rename => [ "Port", "port" ]
rename => [ "PrivilegeList", "[eventlog][privilege_list]" ]
rename => [ "ProcessID", "pid" ]
rename => [ "ProcessName", "[eventlog][process_name]" ]
rename => [ "ProviderGuid", "[eventlog][provider_guid]" ]
rename => [ "ReasonCode", "[eventlog][reason_code]" ]
rename => [ "RecordNumber", "[eventlog][record_number]" ]
rename => [ "ScenarioId", "[eventlog][scenario_id]" ]
rename => [ "Severity", "level" ]
rename => [ "SeverityValue", "[eventlog][severity_code]" ]
rename => [ "SourceModuleName", "nxlog_input" ]
rename => [ "SourceName", "[eventlog][program]" ]
rename => [ "SubjectDomainName", "[eventlog][subject_domain_name]" ]
rename => [ "SubjectLogonId", "[eventlog][subject_logonid]" ]
rename => [ "SubjectUserName", "[eventlog][subject_user_name]" ]
rename => [ "SubjectUserSid", "[eventlog][subject_user_sid]" ]
rename => [ "System", "[eventlog][system]" ]
rename => [ "TargetDomainName", "[eventlog][target_domain_name]" ]
rename => [ "TargetLogonId", "[eventlog][target_logonid]" ]
rename => [ "TargetUserName", "[eventlog][target_user_name]" ]
rename => [ "TargetUserSid", "[eventlog][target_user_sid]" ]
rename => [ "ThreadID", "thread" ]
}
mutate {
remove_field => [
"CurrentOrNextState",
"Description",
"EventReceivedTime",
"EventTime",
"EventTimeWritten",
"IPVersion",
"KeyLength",
"Keywords",
"LmPackageName",
"LogonProcessName",
"LogonType",
"Name",
"Opcode",
"OpcodeValue",
"PolicyProcessingMode",
"Protocol",
"ProtocolType",
"SourceModuleType",
"State",
"Task",
"TransmittedServices",
"Type",
"UserID",
"Version"
]
}
}
}
output {
elasticsearch {
hosts => ["localhost:9200"]
}
if "Token validation failed" in [message] {
email {
address => "smtp01.domain.com"
to => "example#domain.com"
from => "Sender#domain.com"
subject => "Auth Issue"
body => "Auth Issue"
port => 25
use_tls => false
via => "smtp"
}
}
} # end output
I would like to know how to get the email to send only if the message tag "Token validation failed" 10 times in one minute. If it has 9 or below entries it will not send any emails. What config do I need to setup to get this to work?
There are a few ways to achieve that.
A. You can use XPack Alerting (formerly called Watcher) or ElastAlert as described in this answer
B. You can use the aggregate Logstash filter in order to keep track and count the "Token validation failed" messages as described in this answer. You simply need to
aggregate {
task_id => "%{[eventlog][target_logonid]}"
code => "map['failed_count'] ||= 0; map['failed_count'] += 1;"
push_map_as_event_on_timeout => true
timeout => 60 # 1 minute timeout
timeout_tags => ['_aggregatetimeout']
timeout_code => "event.set('token_failed', event.get('failed_count') >= 10)"
}
Then you can send your email only if [token_failed]
C. You can use the ruby Logstash filter in order to count and cache the number of times the "Token validation failed" message has occurred. It's basically the same as B but by implementing the logic yourself in Ruby code.
D. You can use the metrics Logstash filter in order to compute the rate of events having "Token validation failed" in the message field.
metrics {
meter => [ "message" ]
rates => [ 1 ]
add_tag => "metric"
}
Then in your output you can simply use the metered info like this:
if "metric" in [tags] and [Token validation failed][count] >= 10 {
email {
...
}
}
Note that with solutions B and C you cannot launch Logstash with more than one worker (i.e. -w 1). I've filed an enhancement request to "fix" that issue, but since the Logstash team already has a huge pipeline of TODOs, we'll see what happens.