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'");
Related
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;
}
}
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 created a custom rocksolid content element. Now I would like to have pagination for that content element in the frontend. Is it possible to have pagination to be configured with rocksolid custom content element. If so, how it is possible? My config file is
'inputType' => 'list',
'fields' => array(
'html' => array(
'label' => array(
'en' => array('Script code', ''),
'de' => array('Script code', ''),
),
'inputType' => 'text',
'eval' => array('mandatory'=>true, 'allowHtml'=>true, 'class'=>'monospace', 'rte'=>'ace|html', 'helpwizard'=>true),
),
'text' => array(
'label' => array(
'en' => array('Text', ''),
'de' => array('Text', ''),
),
'inputType' => 'textarea',
'eval' => array(
'rte' => 'tinyMCE',
'tl_class' => 'clr',
),
),
Is it possible to add the pagination configuration in this config file? If so what is the configuration?
I am working on Plugin development and my plugin name is plugindev.I have a custom post type called team.I have a custom taxonomy Team_Category which is being registered by this code
/***************************taxonomy****************************/
add_action( 'init', 'create_team_taxonomies', 0 );
function create_team_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
'name' => _x( 'Team_Categories', 'taxonomy general name' ),
'singular_name' => _x( 'Team_Category', 'taxonomy singular name' ),
'search_items' => __( 'Search Team_Categories' ),
'all_items' => __( 'All Team_Categories' ),
'parent_item' => __( 'Parent Team_Category' ),
'parent_item_colon' => __( 'Parent Team_Category:' ),
'edit_item' => __( 'Edit Team_Category' ),
'update_item' => __( 'Update Team_Category' ),
'add_new_item' => __( 'Add New Team_Category' ),
'new_item_name' => __( 'New Team_Category Name' ),
'menu_name' => __( 'Team_Category' ),
);
$args = array(
'hierarchical' => true,
'labels' => $labels,
'show_ui' => true,
'show_admin_column' => false,
'query_var' => true,
'rewrite' => array( 'slug' => 'Team_Category' ),
);
register_taxonomy( 'Team_Category', array( 'team' ), $args );
}
/****************************taxanomy end***********************************/
But when I use a tax_query in my WP_Query, I do not get any posts.
here is my code
<?php
$taxonomy_name = 'Team_Category';
$get_categories = get_terms($taxonomy_name);
$total_categories = count($get_categories);
// Loop through the obituaries:
for ($i = 0; $i < $total_categories; $i++) {
?>
<div class="row">
<div class="col-md-4">
<?php echo $category_name = $get_categories[$i]->name; ?>
</div>
<?php
$args = array(
'post_type' => 'team',
'tax_query' => array(
array(
'taxonomy' => 'Team_Category',
'field' => 'slug', 'terms' => $category_name,)
)
);
$query = new WP_Query($args);
if ($query->have_posts()) {
while ($query->have_posts()) {
$query->the_post();
the_title();
}
}
wp_reset_query(); ?>
</div>
<?php }
It works perfectly without tax_query.I did lot of google but found no suitable result.Any solution to solve this problem .Any help would be highly appreciated
register_taxonomy()
$taxonomy (string) (required) The name of the taxonomy. Name should
only contain lowercase letters and the underscore character, and not
be more than 32 characters long (database structure restriction).
change your taxonomy name from Team_Category to team_category
you should then be able to use argument like this
$arg = array(
'post_type' => 'team',
'taxonomy' => 'team_category',
'term' => 'term_name',
);
//using tax_query
$mytax = get_terms('your_taxonomy');
$arg = array(
'post_type' => 'team',
'tax_query' => array(
array(
'taxonomy' => 'team_category',
'field' => 'slug',
'terms' => 'term_slug', //you need to use slug not name $mytax[0]->slug;
#or
//'field' => 'name',
//'terms' => 'term_name', //you need to use term name $mytax[0]->name;
#or
//'field' => 'term_id',
//'terms' => 'term_ID', //you need to use term ID $mytax[0]->term_id;
),
),
);
WP_Query($nivelquery) and the loop will now print every post registered using my custom taxonomy in $terms, and order them by the meta_key 'salary'.
$terms = get_terms('Team_Category',
array(
'orderby' => 'slug',
'order' => 'ASC',
'hide_empty' => 1,
'fields' => 'ids',
));
$args = array(
'tax_query' => array(
array(
'taxonomy' => 'vagas_tipo',
'field' => 'id',
'terms' => $terms,
),
),
'orderby' => 'meta_value',
'meta_key' => 'salary',
'order' => 'DESC'
);
$query = new WP_Query($args);
I'm looking for a way of dynamically outputting the description of my categories in my custom post type's taxonomy, but I'm over my head in php in how to achieve it. I've read the codex on category_description thorough but without any luck. Also I've looked at this guide from smashing mag.
Really hoping some php wizards can straighten me out
It should look something like this on the multiple frontend displayed custom taxonomy categories
But it looks like this
<a href="#" original-title></a>
What I'm doing is this
<?php echo '<li><a href="#" title="'.$presenter->description.'"</a></li>'; ?>
I'm declaring the $presenter variable like this
$presenter = get_term_by( 'slug', get_query_var( 'term' ), get_query_var( 'portfolio' ) );
And the $presenter variable is based on my custom post_type, which is declared like this
register_post_type('portfolio', array( 'label' => 'Portfolio Items','description' => '','public' => true,'show_ui' => true,'show_in_menu' => true,'capability_type' => 'post','hierarchical' => false,'rewrite' => array('slug' => '%portfolio_page%','with_front'=>true),'query_var' => true,'supports' => array('title','editor','trackbacks','revisions','thumbnail'),'labels' => array (
'name' => 'Portfolio Items',
'singular_name' => 'Portfolio Item',
'menu_name' => 'Portfolio Items',
'add_new' => 'Add Portfolio Item',
'add_new_item' => 'Add New Portfolio Item',
'edit' => 'Edit',
'edit_item' => 'Edit Portfolio Item',
'new_item' => 'New Portfolio Item',
'view' => 'View Portfolio Item',
'view_item' => 'View Portfolio Item',
'search_items' => 'Search Portfolio Items',
'not_found' => 'No Portfolio Items Found',
'not_found_in_trash' => 'No Portfolio Items Found in Trash',
'parent' => 'Parent Portfolio Item',
),) );
And my custom taxonomy is declared like this
function add_custom_taxonomies() {
register_taxonomy('p_category', 'portfolio', array(
'hierarchical' => true,
'labels' => array(
'name' => _x( 'Portfolio Category', 'taxonomy general name', 'theme_x' ),
'singular_name' => _x( 'Category', 'taxonomy singular name', 'theme_x' ),
'search_items' => __( 'Search Category', 'theme_x' ),
'all_items' => __( 'All Categories', 'theme_x' ),
'parent_item' => __( 'Parent Category', 'theme_x' ),
'parent_item_colon' => __( 'Parent Category:', 'theme_x' ),
'edit_item' => __( 'Edit Category', 'theme_x' ),
'update_item' => __( 'Update Category', 'theme_x' ),
'add_new_item' => __( 'Add New Category', 'theme_x' ),
'new_item_name' => __( 'New Category Name', 'theme_x' ),
'menu_name' => __( 'Portfolio Categories', 'theme_x' ),
),
'rewrite' => array(
'slug' => 'portfolio-category',
'with_front' => false,
'hierarchical' => true
),
)
);
};
Just in case if this helps.
You really do not need to go in that much details. Simply echo out the function category_description(), this displays out the description of the custom taxonomy term. Just make sure you have description added for your Custom taxonomy term at yourwpurl.com/wp-admin/edit-tags.php?taxonomy=custom-taxonomy-slug