Sylius - Taxon not Showing Products Assigned to it - sylius

I'm having some trouble getting products to show under the taxon they are assigned to.
I've assigned multiple products to a top-level taxon. I've double-checked to make sure that this setting saved, and they're definitely associated.
If I click on the "Browse Products" button on the taxon grid, I see a message saying that no products were found.
If I visit that taxon's front-end page: /t/taxon-name I also see the same error: There are no products to display.
In the code, I've checked the taxon object's getProducts() function, and it seems to return an empty collection:
ProductController.php on line 75:
Taxon {#4409 ▼
#file: null
#path: null
#products: PersistentCollection {#4370 ▼
-snapshot: []
-owner: Taxon {#4409}
-association: array:15 [ …15]
-em: EntityManager {#2849 …10}
-backRefFieldName: "taxons"
-typeClass: ClassMetadata {#4479 …}
-isDirty: false
-initialized: false
-coll: ArrayCollection {#4371 ▼
-elements: [] <----------------------------- this here
}
}
#id: 13
#code: "test"
#root: Taxon {#4369 ▶}
#parent: Taxon {#4369 ▶ …2}
#children: PersistentCollection {#4372 ▶}
#left: 2
#right: 3
#level: 1
#translations: PersistentCollection {#4375 ▶}
#currentLocale: "en_US"
#currentTranslation: TaxonTranslation {#4377 ▶}
#fallbackLocale: "en_US"
#createdAt: null
#updatedAt: null
}
in the DB in sylius_product I see that multiple products show my taxon id under 'main_taxon_id'. I don't, however, see the products listed in sylius_product_taxon. Is this a problem? Perhaps it is because I'm using main taxons (top-level), rather than lower level taxons? If so, I need to be able to use only one level of taxon, so I'm looking for a solution.

Related

Google Docs API for creating invoice containing table of variable number of rows

I have a template file for my invoice with a table with sample row, but I want to add more rows dynamically based on a given array size, and write the cell values from the array...
Template's photo
I've been struggling for almost 3 days now.
Is there any easy way to accomplish that?
Here's the template file: Link to the Docs file(template)
And here's a few sample arrays of input data to be replaced in the Template file:
[
[
"Sample item 1s",
"Sample Quantity 1",
"Sample price 1",
"Sample total 1"
],
[
"Sample item 2",
"Sample Quantity 2",
"Sample price 2",
"Sample total 2"
],
[
"Sample item 3",
"Sample Quantity 3",
"Sample price 3",
"Sample total 3"
],
]
Now, the length of the parent array can vary depending on the number of items in the invoice, and that's the only problem that I'm struggling with.
And... Yeah, this is a duplicate question, I've found another question on the same topic, but looking at the answers and comments, everyone is commenting that they don't understand the question whereas it looks perfectly clear for me.
Google Docs Invoice template with dynamically items row from Google Sheets
I think the person who asked the question have already quit from it. :(
By the way I am using the API for PHP (Google API Client Library for PHP), and code for replacing dummy text a Google Docs Document by the actual data is given below:
public function replaceTexts(array $replacements, string $document_id) {
# code...
$req = new Docs\BatchUpdateDocumentRequest();
// var_dump($replacements);
// die();
foreach ($replacements as $replacement) {
$target = new Docs\SubstringMatchCriteria();
$target->text = "{{" . $replacement["targetText"] . "}}";
$target->setMatchCase(false);
$req->setRequests([
...$req->getRequests(),
new Docs\Request([
"replaceAllText" => [
"replaceText" => $replacement["newText"],
"containsText" => $target
]
]),
]);
}
return $this->docs_service->documents->batchUpdate(
$document_id,
$req
);
}
A possible solution would be the following
First prep the document by removing every row from the table apart from the title.
Get the full document tree from the Google Docs API.
This would be a simple call with the document id
$doc = $service->documents->get($documentId);
Traverse the document object returned to get to the table and then find the location of the right cell. This could be done by looping through the elements in the body object until one with the right table field is found. Note that this may not necessarily be the first one since in your template, the section with the {{CustomerName}} placeholder is also a table. So you may have to find a table that has the first cell with a text value of "Item".
Add a new row to the table. This is done by creating a request with the shape:
[
'insertTableRow' => [
'tableCellLocation' => [
'rowIndex' => 1,
'columnIndex' => 1,
'tableStartLocation' => [
'index' => 177
]
]
]
]
The tableStartLocation->index element is the paragraph index of the cell to be entered, i.e. body->content[i]->table->startIndex. Send the request.
Repeat steps 2 and 3 to get the updated $doc object, and then access the newly created cell i.e. body->content[i]->table->tableRows[j]->tableCells[k]->content->paragraph->elements[l]->startIndex.
Send a request to update the text content of the cell at the location of the startIndex from 5 above, i.e.
[
'insertText' => [
'location' => [
'index' => 206,
]
],
'text' => 'item_1'
]
]
Repeat step 5 but access the next cell. Note that after each update you need to fetch an updated version of the document object because the indexes change after inserts.
To be honest, this approach is pretty cumbersome, and it's probably more efficient to insert all the data into a spreadsheet and then embed the spreadsheet into your word document. Information on that can be found here How to insert an embedded sheet via Google Docs API?.
As a final note, I created a copy of your template and used the "Try this method" feature in the API documentation to validate my approach so some of the PHP syntax may be a bit off, but I hope you get the general idea.

Sanity io show blog posts by author

I'm learning Sanity io CMS and GROQ. I've build a simple blog using one the Sanity predefined blog schema. I've managed to show posts, a single post and the author page, showing name, image and bio.
What I would like to do is to show a list of the blog posts belonging to the author in his page. In the posts schema there is a reference to the author:
{
name: 'author',
title: 'Author',
type: 'reference',
to: {type: 'author'},
},
I've tried to add an array reference to post in the Author schema, but the result is that in the CMS I need to manually add posts to the author. While, I'd like to query the author and return the posts belonging to the author since there's a reference to it in the posts schema , but cannot find how to do it. Is it possibly more a GROQ query than a schema problem, or both?
Found the answer myself by looking at the Sanity documentation in the Query Cheat Sheet page. It was not a scheme problem but rather a GROQ query one. In the author page, in the query that shows the author bio etc. I've added another part in which I'm querying for the posts by that author:
// GROQ Query
sanityClient
.fetch(
`*[_type == "author"]{
name,
bio,
"authorImage": image.asset->url,
"posts": *[_type == "post" && author._ref in *[_type=="author" && name == name ]._id ]{
title,
"slug": slug.current,
}
}`
)
.then((data) => setAuthor(data[0]))
.catch(console.error);
Then I can simply map through "posts", using the "slug" to build the URL to the single post.
{author.posts &&
author.posts.map((p) => {
return (
<li>
<a href={`/post/${p.slug}`}>{p.title}</a>
</li>
);
})
}
if you want to reach author by his posts, you can do this:
*[_type == "post"]{
_id,
title,
author->{ // here to reach author name and image you should type ->
name,
image
},
description,
mainImage,
slug
}
If you have an array of authors on a post the following syntax will retrieve all posts for the current author:
`*[_type == "author"]{
name,
bio,
"authorImage": image.asset->url,
"posts": *[_type == "post" && author._ref in authors[]->author._id ]{
title,
"slug": slug.current,
}
}`

azure DevOps API not returning all fields for WorkItems

I'm trying to execute a POST request with Azure DevOps on my WorkItems and get all the Others Tags on the WorkItems .
This is my query
https://dev.azure.com/{orgenezation}/{project}/{Team}/_apis/wit/wiql?api-version=5.1
and the Body is
{
"query": "select [System.Id],[System.Description], [System.WorkItemType], [System.Title], [System.AssignedTo], [System.State], [System.Tags] from WorkItems where [System.TeamProject] = #project and [System.Tags] contains 'Automation' and [System.Tags] contains 'board1'"
}
from some reason I do not get the right data and have missing data from the result , like Description,Tags.
...
"workItems": [
{
"id": 6441,
"url": "https://dev.azure.com/{org}/eb25462e-351c-4364-a55a-e9e6029bffba/_apis/wit/workItems/6441"
},
{
"id": 6442,
"url": "https://dev.azure.com/{org}/eb25462e-351c-4364-a55a-e9e6029bffba/_apis/wit/workItems/6442"
},
...
what should I do with this issue?
It works as designed. It returns only ids and urls. Here you can find the example with request and result: Wiql - Query By Wiql. Then you can use Work Items - Get Work Items Batch and specify all ids from your wiql result. Additionally, you can specify only needed fields: Get list of work items for specific fields.

How to turn string output from sql to integer?

I am generating charts using google chart api. I have done it locally and successfully produce the charts. However, when I transfer them to server (cpanel) the charts is ruined. I have detected that the output of sql query for generating the charts value is produced in string format with "6".
This is the code to get the charts' value:
public function gender()
{
$data = DB::table('results')
->select(
DB::raw('gender as gender'),
DB::raw('count(*) as number'))
->groupBy('gender')
->get();
//dd($data);
$array[] = ['Gender', 'Number'];
foreach($data as $key => $value)
{
$array[++$key] = [$value->gender, $value->number];
}
//dd($array);
return view('gender')->with('gender', json_encode($array));
}
In my local, I try to access the data of the sql using dd($data); producing:
Collection {#263 ▼
#items: array:2 [▼
0 => {#264 ▼
+"gender": "female"
+"number": 6
}
1 => {#266 ▼
+"gender": "male"
+"number": 6
}
]
}
I tried accessing in server using same dd($data);
Collection {#260 ▼
#items: array:2 [▼
0 => {#261 ▼
+"gender": "female"
+"number": "6"
}
1 => {#263 ▼
+"gender": "male"
+"number": "6"
}
]
The difference is the number value from server code is in string.
Why this happened and how to fix the problem?
I had a similar issue. It seems it's a PHP issue. Are you running the same PHP versions on local and production?
In any case, you could also explicitly cast it as an UNSIGNED integer. I was able to do that with the following:
$data = DB::table('results')
->selectRaw('gender as gender, CAST(count(*) AS UNSIGNED) as number')
->groupBy('gender')
->get();

how to filter Defect search by active projects in Rally using Web API

I built a custom search tool to allow searching Rally via the Web API from other applications and I've run into an issue. Right now I am allowing defects to be searched but I noticed that defects are coming back in the search results that are related to a project that is closed. I need to filter these out. I am wondering if there is a way to access attributes on a referenced object when querying another object, for example, if I have a query to search for defects where the name contains some text, such as https://rally1.rallydev.com/slm/webservice/v2.0/defect?query=(Name contains "keyword"), can I include something in that query to say that I only want defects for open projects by using the Project attribute on Defect, such as Project.State equals "Open". Basically I'm wondering if there is a way to do it in one query in an OData-ish format. Or as an alternative, if I separately query for a list of all open projects, could I add conditions to the query to say something like (Name contains "keyword") AND (ProjectId = ... OR ProjectId OR ...)? Any thoughts or suggestions are much appreciated.
A query for defects (or any other work item types) is not expected to return items from closed projects. WS API queries do not search closed projects.
Created a defect in a project. It happens to have FormattedID DE529
Tested (FormattedID = DE529) in WS API.
This json was returned:
{
QueryResult: {
_rallyAPIMajor: "2",
_rallyAPIMinor: "0",
Errors: [ ],
Warnings: [ ],
TotalResultCount: 1,
StartIndex: 1,
PageSize: 20,
Results: [
{
_rallyAPIMajor: "2",
_rallyAPIMinor: "0",
_ref: "https://rally1.rallydev.com/slm/webservice/v2.0/defect/36182496495",
_refObjectUUID: "aa35839a-5e49-44c6-8be7-2fb17bbd91bf",
_refObjectName: "bad defect",
_type: "Defect"
}
]
}
}
Closed the project. Ran the same query:
No result:
{
QueryResult: {
_rallyAPIMajor: "2",
_rallyAPIMinor: "0",
Errors: [ ],
Warnings: [ ],
TotalResultCount: 0,
StartIndex: 1,
PageSize: 20,
Results: [ ]
}
}
Also, it is not possible to query Projects by State. This query will return 0 results even when there are closed projects in the workspace 1234:
https://rally1.rallydev.com/slm/webservice/v2.0/project?workspace=https://rally1.rallydev.com/slm/webservice/v2.0/workspace/12345&query=(State = Closed)
Project names in Rally do not have to be unique. Identifying a project by Name may produce a misleading result in a corner case when you have two projects with the same name(one is Open, the other is Closed).