How to show the store name in the grid in the Magento - magento

I have my custom module in the admin. I have listed the values from the database in the grid. The values are store specific, so every row have the store_id. While listing the value, i also want to display the store name and website name in the row. How can i fetch the store_name and website name in the grid. e.g i have the store_id 5 inserted in the row.
I want the output like
Location Value Store
xyz xyz English

If you put below code in your module grid file then you are able to display Store name in your grid, here's a code
$this->addColumn(’store_id’, array(
‘header’ => Mage::helper(’sales’)->__(’Website’),
‘index’ => ‘store_id’,
‘type’ => ‘store’,
‘width’ => ‘100px’,
‘store_view’=> true,
‘display_deleted’ => true,
));
Further Information you can refer this Link

So you have store_id and you want to display the store name right ?
So use below code to get the store name
$storeId = 5;
$storeName = Mage::getModel('core/store')->load($storeId)->getName();

Related

Add row manually to eloquent result in Laravel 4.2

I am using Laravel 4.2 and i fetch all locations with this code:
$locations = Location::all();
This Locations are displayed in a select box afterwards. How can i add an additional row to the results in order to show an empty first option in the select box.
The options then should be:
choose a location
location 1
location 2
...
I just want to add an additional item to the result in $locations.
Thanks in advance
You can use:
{!! Form::select('location', ['' => 'Select your location'] + $locations, null , ['class' => 'form-control']) !!}
to update the view. In Laravel 5 there are attribute accessors to append an extra field with your eloquent collection.
Few other ways to do this are:
$locations[null] = 'choose a location';
Form::select('location', $locations);
Form::select('location',[null=>'Please Select'] + $locations);
Another way is to loop through the result and update it. Use json_decode() or 'toArray()` to convert your result into array format.
Otherwise you have to store choose a location as the first row value in your locations table(I know that is inappropriate for the requirement).
You should look at the put method for collections:
https://laravel.com/docs/5.6/collections#method-put
This method is not available in 4.2. You should make a custom Collection class and use it in your model by overwriting the newCollection method. https://laravel.com/docs/4.2/eloquent#collections

Prestashop product combination display on product list

I am trying to get available product combination (size) in product list page on each product. Basically there is a image, product name, available combinations, price, buy button.
I tried to out put $product object, but it does not have combination variable to it.
Is there any way to achieve that?
There is function assignAttributesGroups() in the ProductController.php from where you can get code for size combination.
protected function assignAttributesGroups()
{
...
...
...
$this->context->smarty->assign(array(
'groups' => $groups,
'colors' => (count($colors)) ? $colors : false,
'combinations' => $combinations,
'combinationImages' => $combination_images
));
}
If you print the value of groups you will get desired output. The combinations has been arranged to show dropdown in product.tpl(/PRESTASHOP_FOLDER/themes/default-bootstrap/product.tpl) as shown in image
You can take a code from the function mentioned above and run it for every product in the list. You have to create a product object and receive combination through it. And create a drop down for the same.

Laravel attach with extra field

I have 3 tables, products, images and product_image. The 3rd one is a pivoting table. Other than product_id and image_id in product_image table, I also have 2 extra fields in this pivoting table: position and type, now for an existing product model A, how do I attach an image to A and at the same time set up its position and type value in that pivoting record? Thanks.
You may try something like this:
$product = Product::find(1);
// if you need also to save the image
$image = new Image(array('foo' => 'bar'));
$product->images()->save($image,array('position'=>'foo', 'type'=>'bar' ));
// if you know image id
$product->images()->attach([$imageId => ['position'=>'foo', 'type'=>'bar']]);
You need just add a array to attach method as second parameter
//for example:
$product->images()->attach($newImage, ['foo'=>'bar']);
It is more eloquent solution.

how to get the size of product to the cart page

I have size of product (XS, XL, ...).
I want add column in cart table Size, where show sizes of products.
I added SKU in this table $_item->getSku(); This works.
But $_item->getSize(); not works. Please, help me.
try adding ->addFieldToSelect('*'), it'll add every attribute associated with your products in the returning data, you can replace the * with the attribute code of the attribute your trying to display
problem is, it'll return integers that are used in either eav_attribute_option or eav_attribute_option_value (not sure why there's 2 different tables, one has values and one has sort order, it's not like Magento even links a value to 2 options), however if you use the following code
$attributeInfo = Mage::getResourceModel('eav/entity_attribute_collection')->setCodeFilter('ATTRIBUTE_CODE')->getFirstItem();
$sizeValues = array();
// populates sizevalue array with data
foreach ($attributeOptions as $key => $value)
{
$sizeValues[$value['value']] = $value['label'];
}
you get an array of values with their index's being that of that it returned in your collection

Magento addFieldToFilter allow NULLs

When using the Magento collection method addFieldToFilter is it possible to allow filtering by NULL values? I want to select all the products in a collection that have a custom attribute even if no value is assigned to the attribute.
I see you already found a solution, but there is also this option:
$collection->addFieldToFilter('parent_item_id', array('null' => true));
But if you want to use "NULL" => false, which DOESN'T WORK.
(and I noticed you can use elements such as "in", "nin", "eq", "neq", "gt"), you can do this:
$collection->addFieldToFilter('parent_item_id', array('neq' => 'NULL' ));
Hope this is still helpful...
This works for NOT NULL filters
$collection->addFieldToFilter('parent_item_id', array('notnull' => true));
Filtering a product collection by null/empty attributes has two possible solutions. Magento uses an INNER JOIN to grab the values of the attributes to filter. BUT if the product attribute is not assigned a value the join will fail, as a database table / relationship is missing.
Solution #1: Use addAttributeToFilter() and change the join type from "inner" (the default) to "left":
$collection = Mage::getModel('catalog/product')->getCollection();
$collection->addAttributeToFilter('custom_attribute', array( ... condition options ..), 'left');
Solution #2: Make sure your custom attribute has a default value. Magento is conservative in this regard. Magento will only create the relationship between an attribute and a product if a value is given for the attribute. So in the absence of user-specified value or a default value the attribute will not be accessible for filtering a product even if the attribute appears in the product detail view under the admin panel.
Because the question does not match exactly the title of the question and I found the them multiple times by searching for a condition like: special VALUE OR NULL
If you want to filter a collection matching a VALUE OR NULL, then you can use:
$collection->addFieldToFilter('<attribute>', array(
array('eq' => '<value>'),
array('null' => true)
));
You don't need to use addFieldToFilter.
now the solution:
attributes name is known as code in magento, you just need to use the code below to get all of the products which have a specific attribute as an array
$prodsArray=Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('custom_attribute_code')
->getItems();
you can also specify certain conditions for attribute's value in addAttributeToFilter in the second parameter of addAttributeToFilter.
you can find this method in this file (for further study):
app/code/core/Mage/Eav/Model/Entity/Collection/Abstract.php

Resources