Sonata Admin Bundle Search: NonUniqueResultException as Result - symfony

When I try to use the search-function in the Sonata Admin Bundle I always get:
An exception has been thrown during the rendering of a template ("The
query returned a row containing multiple columns. Change the query or
use a different result function like getScalarResult().") in
SonataAdminBundle:Core:search.html.twig at line 53.
NonUniqueResultException: The query returned a row containing multiple
columns. Change the query or use a different result function like
getScalarResult().
When I do the search in the productive environment I just get a result if the Admin-Class has no result:
e.g. for Countries (CountryAdmin Class): no result found
I am using sonata-project/admin-bundle (2.3.10)
I tried to reduce my admin-classes to a single one which is very basic - but still having this problems. Any ideas? Thanks...

I had problem with getScalarResult() method, when i did groupBy into my Admin class in createQuery() method.
Maybe it will help
https://groups.google.com/forum/#!topic/sonata-users/cBT09egDtuo
https://github.com/sonata-project/SonataDoctrineORMAdminBundle/issues/297

Related

Using handlebars to filter specific products from a JSON object?

Kind of a weird and specific question but here I go.
I can currently pull all my products through YAML and through some really brute-force methods, I would be able to sort the product out by custom fields.
I have a multiple choice wizard the user has to fill and in the end, I get an object that looks something like this:
{
stoneType: ['Granite', 'Quartz', 'Glass'],
stoneFinish: ['Polished', 'Honed'],
stoneConcern: ['Floor Care'],
labels: ['Daily Cleaning', 'Stain Removal']
}
I can't (or at least I don't know how) to get this data into my HTML to use the data stored in my YAML code and render the specific products.
I believe I can solve this issue if I were able to pass the array of products into javascript using some sort of handlebars helper(?) but Bigcommerce doesn't allow for custom helper functions.
I read online that you can bypass this by installing handlebars but that is not working for me.
When I installed handlebars through NPM, I get this error:
GET http://localhost:3000/stencil/00000000-0000-0000-0000-000000000001/dist/theme-bundle.main.js 404 (Not Found)
Is there a way for me to get custom helper functions working or another possible idea to sort & filter the products?
Thank you, appreciate the help.
EDIT: I have also tried manually downloading Handlebars.js including the file but I get the error Handlebars is not defined. I must be doing something wrong...

How to loop a "Multiple String" from a ProductBO object in an ISML-Template?

How can I loop a Multiple String from a ProductBO object? What is the best way to do this?
As long as you know the name of the attribute you may use the following method on ProductBO from within an ISML:
public AttributeValue getAttributeValue(String aName);
The storefront app comes with a convenient albeit not extremely flexible module that is able to display AV-s. It works for multiple attributes too. The name of the module is ISCustomAttribute.
Sample usage:
<isCustomAttribute
attributelabel="#AttributeDescriptor:DisplayName#"
attributevalue="#ProductBO:AttributeValue(AttributeDescriptor:ID)#"
attributeseparator=", ">
The best would be if you use this module. You may see it in action. Custom ProductBO attributes are printed on the product details page in the storefront as the next image shows (#see DetailsTab.isml):
If this does not fit, you will have to retrieve the attribs as something iterable. The way I think fits best is to use the BO extension BusinessObjectAttributes. You will be able retrieve a BusinessObjectAttribute by name from it and loop through its value.
<isloop iterator="BusinessObjectAttribute:Value" alias="AValue" counter="counter">
<!--- Do something gorgeous here --->
</isloop>

How do I test for an invalid WordPress WP_Query query?

I have a page template which displays a list of post summaries, depending on a user-defined custom query, which is supplied using the post_content, for example:
category_name=blog
This is then passed to WP_Query() which will return however many 'blog' posts there are.
However, if I pass a completely invalid query (or simply make a mistake) such as:
the rain in spain falls mainly on the plain
WP_Query->get_posts() will return ALL posts in the database, rather than letting me know that the query is meaningless / erroneous.
Is there a built-in method to test for invalid queries?
Currently, I'm doing a parse_str() to convert the query to an array, then an array_intersect_keys() against a list of valid query parameters I've compiled from the WP_Query page.
It works, but feels pretty hacky - am I missing something?
Thanks,
Dave
I don't believe there is a failed query catch built in to WP like you are asking for (I wish there were, too).
However, there may be a cleaner hack. wp_count_posts will return a count of all posts in the database. And wp_query will return a count of its results in $post_count. One thing you could do is a check on your query - if the result of wp_count_posts is equal to $post_count then you know something is wrong.
It's not as clean as a 'no results' response, but perhaps more straight forward than your current solution.
http://codex.wordpress.org/Function_Reference/wp_count_posts
http://codex.wordpress.org/Class_Reference/WP_Query (search the page for $post_count)

How to use GET and POST Arguments in Symfony2

We are transforming PHP Application to Symfony2 Application.
Most of the pages we are completely writing new but some pages we decided to keep it as it is. i.e I want to use the same php without any major change.
In the php page we used GET['prospect_id'], GET['executive_id'] and many other arguments. Both GET and Post methods. When I view the page in Symfony1.4 there is no error or warning.
But when I view in Symfony 2 I am getting undefined index error.
How can I solve the issue?
EDIT: if GET['prospect_id'] is null there is no error in Symfony 1.4 but i'm getting undefined index notice in Symfony2. There are many variables like that. Is it necessary to define variable before use it. How to avoid this notice message.
What i want is if i am using $_GET['xxx']. symfony2 should not show any notice or error. i want to escape from that.
Use (in Symfony2) the controllers request-object, to get those params:
$this->request->get('prospect_id');
$this->request->get('executive_id');
You can also set default values, if there is no value given. Take a look at this documentation.

filter functions problem

I'm working on a search component for an app I'm working on and I needed to add some filters to it. I've found an example and got the first filter working fine.
Now I'm trying to add a second filter I'm running into problems... In the example I found they use filterFunctions, but I only get an option for filterFunction, why is that?
Here's the example code
productsCollection.filterFunctions =
[
filterByPrice, filterByType,
filterByCondition, filterByVendor
]
And this is what I'm trying
acData.filterFunction = [filterByStatus, filterByDate]
but with this code I get the following error message - 1067: Implicit coercion of a value of type Array to an unrelated type Function.
Why am I getting this error and how would I go about add multiple filters to my Array Collection?
Thanks!
filterFunction must be set to a single function, not an Array or any other datatype. To combine multiple functions create one that combines them, like this:
acData.filterFunction = function(item:Object)
{
return
filterByPrice(item) &&
filterByType(item) &&
filterByCondition(item) &&
filterByVendor(item);
};
If you saw a sample that used filterFunctions plural that accepted an array, post a link. That's not anywhere in the standard Flex framework or in the new 4.0 beta afaik.
It looks like you are going to have to extend an arraycollection to make it work. this link should spell it out for you: http://blog.rotundu.eu/flex/arraycollection-with-multiple-filter-functions/

Resources