I use the route-helper ({{ route('routename') }}) in my Blade template files to filter and/or sort the results of the page.
What is the easiest way to attach a parameter to the previous ones?
As an example:
I visit the page /category1 and see some products. Now I use the sorting which changes the URL to /category1?sort_by=title&sort_order=asc
If I use another filtering now, I would like the parameter to be appended to the current one. So to /category1?sort_by=title&sort_order=asc&filter_by=year&year=2017 but the result is only /category1?filter_by=year&year=2017 .
I create the Urls with the route-helper like:
route('category.show', [$category, 'sort_by' => 'title', 'sort_order' => 'asc'])
route('category.show', [$category, 'filter_by' => 'year', 'year' => $year])
You could probably use something like:
$new_parameters = ['filter_by' => 'year', 'year' => $year];
route('category.show', array_merge([$category], request()->all(), $new_parameters]);
to use all previous parameters and add new ones.
Obviously you might want to use only some of them, then instead of:
request()->all()
you can use:
request()->only('sort_by', 'sort_order', 'filter_by', 'year')
Related
I have two collections: "Instructions" and "Known". Basically I am taking a new set of "Instructions" and checking whether anything is different to what is "Known".
So, the quantity is not massive. I retrieve the info:
$Instructions = Instruction::all();
$Knowns = Known::all();
Now, I'm looking for the differences, and I've tried each of these three methods:
$IssuesFound = $Instructions->diff($Knowns);
$IssuesFound = $Instructions->diffKeys($Knowns);
$IssuesFound = $Instructions->diffAssoc($Knowns);
The thing is, an "Instruction" or "Known" is an item with 17 attributes, and anyone of those attributes can be different. I want to compare the attributes of an "Instruction" with the matching attribute of a "Known". (Both items have the same keys, bot items have a Reference attribute to act as a unique identifier.
What I'm finding is that theese methods give me the item that is different, but doesn't tell me which individual attributes are the mismatch.
foreach ($IssuesFound as $issue)
{
dd($issue);
}
So a method like $IssuesFound = $Instructions->diffKeys($Knowns); will come up with item xxx being different, but I can't see how to find out which attribute of the item it is that is different. Not unless I start nesting loops and iterating through all the attributes - which I'm trying to avoid.
How do I do it?
Thanks in advance. (Laravel 5.6)
Straight from laravel docs, diffAssoc will return what you are asking:
$collection = collect([
'color' => 'orange',
'type' => 'fruit',
'remain' => 6
]);
$diff = $collection->diffAssoc([
'color' => 'yellow',
'type' => 'fruit',
'remain' => 3,
'used' => 6
]);
$diff->all();
// ['color' => 'orange', 'remain' => 6]
You get the attribute from the FIRST collection that is different on the SECOND collection, therefore if you get 3 attributes when calling $diff->all() you will know WHICH attributes ARE DIFFERENT, so you could access them or do whatever you want to, if you post more specific results of what you are getting and what you are trying we can help, but I think you are just not thinking how to use these methods
I do:
$this->post('/v1/customer', ['area' => 'kil'])
->seeJson(['created' => true]);
But instead of created => true, I would like to do "NOT STATEMENTS".
Ex: parent!=null or created_at > '0000-00-00'
How can this be achieved?
Laravel does have a dontSeeJson function which would solve both of the examples you've listed (though possibly not a more general case) --
$this->dontSeeJson(['parent' => null]);
$this->dontSeeJson(['created_at' => '0000-00-00']);
If you need something more specific, I agree with #gontrollez - decode the json (json_decode($this->response->getContent(), true)) and test that.
My question comes from seeing this question and not being able to find the correct answer.
When adding a new product, where does the actual code come from for the input fields? In the aforementioned question, the desire is to add maxlength attribute to the input box. I dug around for over an hour and did find plenty of form helpers but not the one for this exact case.
How do I find the true origin of this (or any) form in Magento?
If I'm understanding your question correctly, majority of Magento's form fields come from Varian_Data_Form However you can easily specify a maxlength property via a higher up call, as in:
$fieldset->addField('title', 'text', array(
'label' => Mage::helper('form')->__('Title3'),
'maxlength' => '30', // <-- change here
'class' => 'required-entry',
'required' => true,
'name' => 'title',
'onclick' => "alert('on click');",
'onchange' => "alert('on change');",
'style' => "border:10px",
'value' => 'hello !!',
'disabled' => false,
'readonly' => true,
'after_element_html' => '<small>Comments</small>',
'tabindex' => 1
));
Example (and modified) from:
http://www.excellencemagentoblog.com/magento-admin-form-field
Related:
Extend a Varien Form Element for a Custom Module
Is it good practice to add own file in lib/Varien/Data/Form/Element folder
I accepted B00MER's answer because it led me to what I believe to be the Real Answer...
Clicking on the links he listed, the pattern of $fieldset->addField presented itself as a key way to grep in files.
user#magento:~/www/app$ grep -rin "addField.*text" * | grep -i product
code/core/Mage/Adminhtml/Block/Catalog/Product/Edit/Tab/Super/Config/Simple.php:140: $fieldset->addField('simple_product_inventory_qty', 'text', array(
There were about a dozen results which were quickly narrowed down (we're not caring about giftcard or Attribute sets). I'm not 100% sure THIS file is the answer but it seems that some logic could be added to catch whether or not the input's name=="Name" and then a maxlength could then be added in.
What is the best way to re-order the available sort orders shown in the product list toolbar? Currently, we have 3 sorting options available: Name, Price, Most Popular (in that order). I want to have Most Popular be the left-most item since it is our default sort option. I can write a custom module to extend "getAvailableSortOrders" or something like that, but I thought there had to be an easier way. Anyone have a recommendation?
Brian
The best way I've found so far is to make a copy of
/app/code/core/Mage/Catalog/Model/Config.php
at
/app/code/local/Mage/Catalog/Model/Config.php
and then edit your local copy of the file at line 341
//before
$options = array(
'position' => Mage::helper('catalog')->__('Position')
);
//after
$options = array(
'name' => Mage::helper('catalog')->__('Name'),
'price' => Mage::helper('catalog')->__('Price'),
'position' => Mage::helper('catalog')->__('Best Value')
);
I wanted name to be first, followed by price, and I wanted position to be renamed "Best Value" on the frontend. Since position wouldn't really mean anything to a customer.
I was inspired by this comment on Inchoo.
#jon.niesen: your solution worked only partially. I had no problems renaming 'position' but when it comes to renaming 'name', Magento was very stubborn on this and was still displaying "Name" in the select drop down box.
Maybe in 1.4.1.1 "Name" is hardcoded or something?
This works...
form_dropdown('location', $location_options, $this->input->post('location'));
But when I try and use an array to add extra attributes, it stops working... Why is this?
$attributes = array(
'name' => 'location',
'id' => 'location'
);
form_dropdown($attributes, $location_options, $this->input->post('location'));
The name of the dropdown list is included in the array of attributes so i don't see how this is any different to the first example. Whenever the form is posted posted back, it resets to the start.
Can anyone help me out with this?
Thanks
It's just the wrong syntax.
Please have a look at the docu: http://codeigniter.com/user_guide/helpers/form_helper.html
form_dropdown('location', $location_options, $this->input->post('location'), "id='location'");
Your code should look something like the above. And by the way: if you're using the form_validation library you could use set_value instead of $this->input->post ...
$attributes = ' id="bar" class="foo" onChange="some_function();"';
$location_options = array(
'IN' =>'India',
'US' =>'America'
);
form_dropdown('location', $location_options, $this->input->post('location'),$attributes);
Parameters :
1st param will assign to name of the field,
2nd will get your options,
3rd is for default value,
4th one is for extra properties to add like javascript function, id, class ...