In my custom module, used installData.php to create a custom multiselect attribute. Where i have set the option values from my source class (using Magento\Eav\Model\Entity\Attribute\Source\AbstractSource) which is working fine after installation. I can see the options while editing the product.
But the options are not visible while editing the attribute. Im not able to add/remove option after this.
Please advise.
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'my_option',
[
'group' => 'General',
'label' => 'My Label',
'type' => 'text',
'input' => 'multiselect',
'user_defined' => true,
'global' => \Magento\Eav\Model\Entity\Attribute\ScopedAttributeInterface::SCOPE_STORE,
'source' => 'Vendor\Module\Model\Attribute\Source\Options',
'required' => false,
'filterable' => true,
'filterable_in_search' => true,
'is_searchable_in_grid' => false,
'is_used_in_grid' => false,
'is_visible_in_grid' => false,
'is_filterable_in_grid' => false,
'sort_order' => 200,
'used_in_product_listing' => true,
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'visible' => true,
'visible_on_front' => true,
'searchable' => false,
'comparable' => false,
]
);
1. Create InstallData.php file at Vendor\Extension\Setup\ folder.
<?php
namespace Vendor\Extension\Setup;
use Magento\Eav\Setup\EavSetupFactory;
use Magento\Framework\Setup\InstallDataInterface;
use Magento\Framework\Setup\ModuleContextInterface;
use Magento\Framework\Setup\ModuleDataSetupInterface;
class InstallData implements InstallDataInterface
{
private $eavSetupFactory;
public function __construct(EavSetupFactory $eavSetupFactory)
{
$this->eavSetupFactory = $eavSetupFactory;
}
public function install(ModuleDataSetupInterface $setup, ModuleContextInterface $context)
{
$setup->startSetup();
$eavSetup = $this->eavSetupFactory->create(['setup' => $setup]);
$eavSetup->addAttribute(
\Magento\Catalog\Model\Product::ENTITY,
'eway_option',
[
'group' => 'Groupe Name',
'label' => 'Multiselect Attribute',
'type' => 'text',
'input' => 'multiselect',
'source' => 'Vendor\Extension\Model\Config\Product\Extensionoption',
'required' => false,
'sort_order' => 30,
'global' => \Magento\Catalog\Model\ResourceModel\Eav\Attribute::SCOPE_STORE,
'used_in_product_listing' => true,
'backend' => 'Magento\Eav\Model\Entity\Attribute\Backend\ArrayBackend',
'visible_on_front' => false
]
);
$setup->endSetup();
}
}
2. Create Extensionoption.php file at Vendor\Extension\Model\Config\Product folder.
<?php
namespace Vendor\Extension\Model\Config\Product;
use Magento\Eav\Model\Entity\Attribute\Source\AbstractSource;
class Extensionoption extends AbstractSource
{
protected $optionFactory;
public function getAllOptions()
{
$this->_options = [];
$this->_options[] = ['label' => 'Label 1', 'value' => 'value 1'];
$this->_options[] = ['label' => 'Label 2', 'value' => 'value 2'];
return $this->_options;
}
}
Related
I have created one product using api of shopware.
Reference: https://developers.shopware.com/developers-guide/rest-api/api-resource-article/
This product(article) is listed in Item -> Overview of shopware. But when I edit this product and try to Preview this product(article) that How it looks in front, it does not show in front. It shows :
Unfortunately, this product is no longer available.
Can Someone help me why this product is not showing in front? I want to show the article in the front which I have created using API in my Plugin.
My array for insert article data in shopware is following.
$client->post('articles',
array(
'name' => 'Damen Organic T-Shirt',
'description' => 'Description',
'descriptionLong' => 'Test Description',
'active' => 1,
'taxId' => 1,
'metaTitle' => '',
'keywords' => '',
'changetime' => date("Y-m-d H:i:s"),
'notification' => 0,
'supplier' => 'Shirtee',
'categories' => 'Shopware',
'mainDetail' => array(
'number' => 'MO1C38Q',
'inStock' => 1,
'weight' => '1.000',
'position' => '1',
'width' => null,
'height' => null,
'attribute' => array(
'attr1' => '',
),
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => 50,
),
),
),
'images' => array(
'link' => 'test.png'
),
'configuratorSet' => array(
'groups' => array(
array(
'name' => 'Size',
'options' => 'M'
),
array(
'name' => 'Color',
'options' => 'Green'
),
)
)
));
Your answer will really help me out.
It is required to pass active => true within mainDetail as shown in the example:
$minimalTestArticle = array(
'name' => 'Sport Shoes',
'active' => true,
'tax' => 19,
'supplier' => 'Sport Shoes Inc.',
'categories' => array(
array('id' => 15),
),
'mainDetail' => array(
'number' => 'turn',
'active' => true,
'prices' => array(
array(
'customerGroupKey' => 'EK',
'price' => 999,
),
)
),
);
$client->post('articles', $minimalTestArticle);
Following is the query that you can find within engine/Shopware/Bundle/StoreFrontBundle/Service/Core/ProductNumberService.php -> isNumberAvailable
SELECT variant.ordernumber FROM s_articles_details variant INNER JOIN s_articles product ON product.id = variant.articleID AND variant.active = 1 WHERE (variant.ordernumber = 'number') AND ((variant.laststock * variant.instock) >= (variant.laststock * variant.minpurchase)) LIMIT 1
Also, it is required to set active => true for each variation if you creating them.
I am new to Yii-2.
I have a grid-view in my index page which some entries are displaying.
<?= GridView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'meter_id',
[
'label' => 'Meter MSN',
'value' => function ($d) {
return $d->meter->meter_msn;
},
// 'filter' => Html::activeDropDownList($searchModel, 'meter_id', \app\models\Meters::toArrayList(), ['prompt' => "All Meters", 'class' => 'form-control']),
],
'imsi',
'telecom',
'status',
[
'label' => 'Created By',
'value' => function ($data) {
if (is_object($data))
return $data->created->name;
return ' - ';
},
//'filter' => Html::activeDropDownList($searchModel, 'created_by', \app\models\User::toArrayList(), ['prompt' => "Created By", 'class' => 'form-control']),
],
'comments',
'historic',
['class' => 'yii\grid\ActionColumn'],
],
]); ?>
Now I want to add a search-box against Meter MSN. In above code the filter is hidden so it was working but I don't want to add a drop-down instead I want a search box.
Below is my search class
public function search($params)
{
$query = MetersInventoryStore::find();
// add conditions that should always apply here
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
$this->load($params);
if (!$this->validate()) {
// uncomment the following line if you do not want to return any records when validation fails
// $query->where('0=1');
return $dataProvider;
}
// grid filtering conditions
$query->andFilterWhere([
'id' => $this->id,
'meter_id' => $this->meter_id,
'created_by' => $this->created_by,
'updated_by' => $this->updated_by,
'created_at' => $this->created_at,
'updated_at' => $this->updated_at,
'store_id' => $this->store_id,
'meter_serial'=>$this->meter_serial,
// 'historic' => $this->historic,
'status'=>'SIM Installed',
])
// ->orFilterWhere(['status'=>'Communication Failed'])
;
// $query->andFilterWhere(['like', 'meter_serial', $this->meter_serial])
// ->andFilterWhere(['like','meter_id',$this->meter_id]);
$query->orderBy(['id' => SORT_DESC]);
return $dataProvider;
}
How can I place a search-box in it? As the simple search class will set up the search functionality by default. But my MSN value is coming from a function so I have no idea how can I place a search-box.
Any help would be highly appreciated.
for add filter field in a calculated column you should add a pubblic var in
in your search model
public function search($params)
{
public $your_column;
// declare as safe
public function rules()
{
return [
...
[[ 'your_column', ], 'safe'],
];
}
$query = MetersInventoryStore::find();
and then refer to your_column in grid_view
...
'columns' => [
['class' => 'yii\grid\SerialColumn'],
//'meter_id',
[
'attribute' => 'your_column',
'label' => 'Meter MSN',
'value' => function ($d) {
return $d->meter->meter_msn;
},
],
And last your searchModel you must expand your filter condition for manage properly your calculated column based on the filter value you passed.
You can find some sample in this tutorial http://www.yiiframework.com/wiki/621/filter-sort-by-calculated-related-fields-in-gridview-yii-2-0/
I can´t concatenate a label with string.
->add('originador', EntityType::class, array(
'label' => "app.label.x_originador".'*',
'class' => 'AppBundle:Usuario',
'em' => $options['entityManager'],
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u');
},
'placeholder' => '',
'required' => false,
))
In the part of 'label' => "app.label.x_originador".'*',
I need that the result be Originador*,because the label is for required value.
The result that I recieve is app.label.x_originador*
Please, help me to get
Originador* as result.
You can pass the translator service to your form type and translate then concatenate like this:
class MyFormType extends AbstractType
{
private $translator;
public function __construct(TranslatorInterface $translator)
{
$this->translator = $translator;
}
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('originador', EntityType::class, array(
'label' => $this->translator->trans('app.label.x_originador',[], 'domain').'*',
'class' => 'AppBundle:Usuario',
'em' => $options['entityManager'],
'query_builder' => function (EntityRepository $er) {
return $er->createQueryBuilder('u');
},
'placeholder' => '',
'required' => false,
));
}
}
juste replace "domain" with your translation domain.
EDIT: but yeah, the best solution is probably #ccKep's one
My main.php code
<?php
NavBar::begin([
'brandLabel' => 'Styl-dekoracje.pl',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => 'Home', 'url' => ['/site/index']],
['label' => 'Orders', 'url' => ['/order']],
Yii::$app->user->isGuest ?
['label' => 'Login', 'url' => ['/site/login']] :
['label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => ['/site/logout'],
'linkOptions' => ['data-method' => 'post']],
],
]);
NavBar::end();
?>
When I click for login/logout or home item its will be highlight. But how can I disable highlighting for SiteController? Where is file who set item as active?
Each item insive Nav have active property.
Set it depending on current controller, action, or route.
Example:
[
'label' => 'Login',
'url' => ['/site/login'],
'active' => $this->context->route == 'site/login',
],
Setting this for site/logout doesn't make sense because it's immediate action with redirect.
Official documentation:
Nav $items
View $context
Controller $route
I am not familiar with Yii2, but in Yii there was an activeCssClass option.
'activeCssClass' => ''
The code above disbaled the higlighting of active menu item.
You can use Url::to() to make it work. This is just a workaround.
<?php
NavBar::begin([
'brandLabel' => 'Styl-dekoracje.pl',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => 'Home', 'url' => Url::to(['/site/index'])],
['label' => 'Orders', 'url' => Url::to(['/order'])],
Yii::$app->user->isGuest ?
['label' => 'Login', 'url' => Url::to(['/site/login'])] :
['label' => 'Logout (' . Yii::$app->user->identity->username . ')',
'url' => Url::to(['/site/logout']),
'linkOptions' => ['data-method' => 'post']],
],
]);
NavBar::end();
?>
I am facing a problem regarding creating attribute and attribute set using installer script.attribute set and attribute is created but the problem is attributes are assigned to all attribute set instead of only custom one creating with installer script.
following is my installer script:
<?php
$installer = $this;
$installer->startSetup();
try{
$sNewSetName = 'Product Bundler Package';
$iCatalogProductEntityTypeId = (int) $installer->getEntityTypeId('catalog_product');
$oAttributeset = Mage::getModel('eav/entity_attribute_set')
->setEntityTypeId($iCatalogProductEntityTypeId)
->setAttributeSetName($sNewSetName);
if ($oAttributeset->validate()) {
$oAttributeset
->save()
->initFromSkeleton($installer->getAttributeSetId('catalog_product', 'Default'))
->save();
}
else {
Mage::log('Attributeset with name ' . $sNewSetName . ' already exists.');
}
}
catch(Exception $ex){
Mage::log('Attributeset with name ' . $sNewSetName . ' already exists.');
}
$installer->addAttributeGroup('catalog_product', 'Product Bundler Package', 'Bundled Package Data', 1000);
$data1= array (
'attribute_set' => 'Product Bundler Package',
'group' => 'Bundled Package Data',
'label' => 'Preset1 name',
'visible' => true,
'type' => 'varchar',
'input' => 'text',
'system' => true,
'required' => false,
'user_defined' => 1,
);
$installer->addAttribute('catalog_product','bundle_preset1_name',$data1);
$data2= array (
'attribute_set' => 'Product Bundler Package',
'group' => 'Bundled Package Data',
'label' => 'Preset2 name',
'visible' => true,
'type' => 'varchar',
'input' => 'text',
'system' => true,
'required' => false,
'user_defined' => 1,
);
$installer->addAttribute('catalog_product','bundle_preset2_name',$data2);
$data3= array (
'attribute_set' => 'Product Bundler Package',
'group' => 'Bundled Package Data',
'label' => 'Preset3 name',
'visible' => true,
'type' => 'varchar',
'input' => 'text',
'system' => true,
'required' => false,
'user_defined' => 1,
);
$installer->addAttribute('catalog_product','bundle_preset3_name',$data3);
$data4 = array (
'attribute_set' => 'Product Bundler Package',
'group' => 'Bundled Package Data',
'label' => 'Preset4 name',
'visible' => true,
'type' => 'varchar',
'input' => 'text',
'system' => true,
'required' => false,
'user_defined' => 1,
);
$attribute = $installer->addAttribute('catalog_product','bundle_preset4_name',$data4);
$installer->endSetup();
?>
I want to create custom attributes with attribute set name "Product Bundler Package" and assign all attribute to that attribute set only.
Kindly help me to resolve it.
You can add following code before $installer->endSetUp();
/*delete the group from default attribute set in the end of the script */
$resource = Mage::getSingleton('core/resource');
$write = $resource->getConnection('write');
$groupTable = $installer->getTable('eav_attribute_group');
$defaultSetId = $installer->getDefaultAttributeSetId($iCatalogProductEntityTypeId);
$groupNameToRemove = 'Bundled Package Data';
$write->query("Delete from $groupTable where attribute_set_id=$defaultSetId and attribute_group_name='$groupNameToRemove'");