To get data from one table to another in Magento - magento

I have created new module name handmade t-shirt design management in magento. It has t-shirt-design & t-shirt designer. designers will add their design from admin panel. so wen they add t-shirt design, I need to select t-shirt designer using t-shirt designer table, in other words I need id of that designer and want to store it in t-shirt design. How can i do this in MAGENTO?
Please help
.
Thanks in advance

You can make a call to the event
<catalog_product_prepare_save>
And in the Observer you can have the data Values
For example
public function saveProductBrand($observer) {
$product = $observer->getProduct();
$categoryIds = $product->getCategoryIds();
if (isset($categoryIds)) {
foreach ($categoryIds as $categoryId) {
$isBrandCategory = Mage::getModel('brands/navigation')->isBrandCategory($categoryId);
if ($isBrandCategory)
$brandCategories[] = $categoryId;
}
You can Just have a look at HERE

Related

Magento 2 How to pass js variable to controller and then call template with custom code?

I need dynamically change custom attribute on the configurable page when I click to the swatch color attribute. On this purpose I programmatically created custom attributes with options on the admin panel, where I can save for every product his own custom attributes.
I figure out how to call my custom attributes on simple products but I can't to do this with configurable product.
I see when I change color attribute - price is changed for every simple product([it's default thing), how to do same but with my custom attributes?
I have one idea but I don't know how this one implement. So I know how to get current product id when you clicked on the color attribute(through js code) then I need pass this id data to the controller via ajax. I need to know how exactly to do this, how to pass js data through ajax to controller and then call needed block on the category page every time when I click on the color attribute? ? When I will be know how to do that I get with this id data - custom attribute values and call this template in the needed place.
Code below is that what call custom attributes on the configurable product, but it's call all attributes for all simple products included in the configurable product. I need call these attributes for current product every time when I cliked on the color attribute. For example: if I click on the black color (which related to the product with id 123 ) I get custom block with custom attributes without reloading page(like price).color attributes
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$product = $objectManager->get('Magento\Framework\Registry')->registry('current_product');
$product_id = $product->getId();
$configProduct = $objectManager-
>create('Magento\Catalog\Model\Product')->load($product_id);
$configurable = $configProduct->getTypeId() ==
\Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE;
$_children = $configProduct->getTypeInstance()-
>getUsedProducts($configProduct);
if ($configurable){
foreach ($_children as $child){
$child_badge = $child->getResource()->getAttribute('mycustom_attribute_code')->getFrontend()->getValue($child);
echo $child_badge;
}
}

Woocommerce sidebar widget categories sorting not working

I displayed Woocommerce categories widget in sidebar of product archive page. And I tried following code to sort categories in sidebar.
add_filter( 'woocommerce_product_categories_widget_args', 'custom_woocommerce_product_subcategories_args' );
function custom_woocommerce_product_subcategories_args( $args ) {
$args['menu_order'] = 'asc';
return $args;
}
I want to sort categories and sub-categories both, But is not working.
Well, I can say all Product Categories of Woo Commerce is by default sorted by Product Names in ascending order in Product Categories widget. You can use it in any page (e.g. Product landing page, product-single page, archive page etc).
You just need to use Product Categories widget in your sidebar. That's it...

How to update product attributes?

I have thousands of products which have some common default values:
page layout : No layout updates; Visibility:Not Visible Individually;
categoies: empty,
Now I want to change these three attributes once like below:
page layout : 1 column; Visibility:Catalog, Search (4); categoies: 1,
I tried to finish it with below code, but it is not working.
$collection = Mage::getResourceModel('catalog/product_collection')->load();
foreach($collection as $items)
{
$product = Mage::getModel('catalog/product')->load($items->getId());
$product->setVisibility(4);
$product->save();
echo $product->getId().'<br>';
}
Who can tell me what the problem is with my code?
I also tried to finish in database. But I do not know which table can control visibilibty, which table can control layout or category. (Using Magento 1.7)
You can do this directly from the admin area:
Catalog -> Manage Product
Check the article you want to edit and then select "Change attributes" from "Actions" drop down menu.
You can now massively change attribute to your product
Cheers

Magento - How to show the same images for product bundles?

I created a bundled product following the instructions on the Magento site to enable it to have several sizes. See attached image:
I'm supposing that when I do the Quick simple product creation, it doesn't automatically add the same images. But since the option is only for size, the image should be the same.
The problem is, when I go to the cart or checkout page or any other page, there is no image for the product. The combination of my products with the sizes, that s over 230 products, so re-uploading all the images is a nightmare.
Question is, how can I have the system use the same image for all the different sizes?
Thanks.
I had similar problem with configurable products. I wanted the image which I assign to the main product to be added also to all options. So I created an extension and observed catalog_product_save_after event. Then I added this kind of code in my observer:
$product = $observer->getEvent()->getProduct();
if ($product->getTypeId() == Mage_Catalog_Model_Product_Type::TYPE_CONFIGURABLE)
{
$main_image = $product->getImage();
if($main_image != "no_selection")
{
$productTypeIns = $product->getTypeInstance(true);
$childIds = $productTypeIns->getChildrenIds($product->getId());
$importDir = Mage::getBaseDir('media') . DS . 'catalog/product';
foreach ($childIds as $childId)
{
foreach($childId as $_childId)
{
$childProduct = Mage::getModel('catalog/product')->load($_childId); //You get your child products here
if ($childProduct->getImage()=="no_selection")
{
$childProduct->addImageToMediaGallery($importDir.$main_image,array ('image','small_image','thumbnail'),false,false);
$childProduct->save();
}
}
}
}
}

Hide a group in catalog product?

Please help me if anybody know how this work can be done.
I want to hide the website tab in catalog Product, but its functionality should exist. That is, I have made all the check boxes automatically checked,so i dont want to show this tab anybody...but at the time of adding product..check boxes values would be saved.
Not exactly sure how you would do this, but basically you need to bind an Observer in the adminhtml render sequence that calls Mage_Adminhtml_Block_Widget_Tabs::removeTab($tabId) where $tabId is the Id of the websites tab (I think it's just "websites"). The trick is to find the right event to bind your Observer to, #Joseph's list of events should get you started. I would try something like adminhtml_block_html_before.
Your observer would also set the values on the product at the same time.
Good luck,
JD
In ProductController.php
Websites
*/
if (!isset($productData['website_ids'])) {
$productData['website_ids'] = array();
}
$productData['website_ids']=$this->getStoreWebsiteId(); //newly added
//newly added
public function getStoreWebsiteId(){
$selectWebsite="SELECT * from core_website WHERE website_id!=0";
$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$value=$connection->fetchAll($selectWebsite);
foreach($value as $websiteDetails){
$websiteId[]=$websiteDetails['website_id'];
}
return $websiteId;
}

Resources