10

This part caused your issue, if you created this object outsize the foreach loop, that means it is a "global" object. So, we need to create a new object inside the loop. $linkData = $productLinks //Magento\Catalog\Api\Data\ProductLinkInterface It should like this: /** @var \Magento\Catalog\Api\Data\ProductLinkInterfaceFactory $productLinks **/ $linkData =...


8

In app/design/frontend/MyCompany/mytheme/Magento_Catalog/templates/product/list/items.phtml please add below code : <?php if($_item->getTypeId() == \Magento\ConfigurableProduct\Model\Product\Type\Configurable::TYPE_CODE){ $swatchBlock = $this->getLayout()->createBlock("Magento\Swatches\Block\Product\Renderer\Listing\Configurable")->...


5

You can do this with the help of a custom observer method. To do so, call your observer's function at event catalog_product_save_after. By using this, whenever a product will be saved from admin panel, you can check whether the product has related products assigned or not. If it has no related products, then you can assign related products (by product ids) ...


5

You can write an observer for catalog_product_collection_load_after, then add products to the loaded collection if the collection is the related products collection: use Mage_Catalog_Model_Product as Product; use Mage_Catalog_Model_Product_Link as RelatedProduct; use Mage_Catalog_Model_Resource_Product_Link_Product_Collection as RelatedProductCollection; ...


5

Magento 2.0.x version: First of all, there are some notes: --Replaced event catalog_product_prepare_save with controller product initialization helper that can be customized via plugins - Vendor/ProductRelation/Model/Product/Initialization/Helper/ProductLinks.php. --Replaced event catalog_model_product_duplicate with composite Product\Copier model. ...


5

In 2.2.5 we're doing the following to achieve the swatches, essentially it replicates the code from the Mage_Catalog::product/list.phtml template where swatches are by default. Firstly you need to add the swatch renderers to the block via the layout XML for the catalog_product_view layout handle. In app/design/frontend/MyCompany/mytheme/Magento_Swatches/...


4

Adding related product in Magento 2 is very easy. Here are steps Admin -> Product(left sidebar) -> Catalog Click on Edit link under Action tab. Go to Related Products, Up-Sells, and Cross-Sells section of the page Here you can select any number of product and these products will be displayed as related products. Hope it will help someone.


4

I presume you are falling back to the blank or Luma theme? If this is the case you need to move the related products using the <move> XML. <move element="catalog.product.related" destination="block-name-where-you-want-to-place-it" /> And then add the related products to each product through the admin (if you're not using sample data).


4

We've experienced the same issue, it seems import module has some kind of bug with related products We've solved it by writing a new console command which expects a 2 columns (parent sku & children skus) related.csv file in var folder, with comma as csv separator, and pipe as children_skus separator This are the files, if you want to try. You'd replace ...


4

By default, Magento uses the same template for product related, upsell, crosssel and new products content widget. This template comes from vendor/magento/module-catalog/view/frontend/templates/product/list/items.phtml. If we want to custom this template, we should copy it to our current theme: app/design/frontend/{Vendor Theme}/{Theme name}/Magento_Catalog/...


4

Replace the content of if ($showCart) ...... endif with below code. <?php if ($showCart): ?> <div class="product actions product-item-actions"> <form data-role="tocart-form" action="<?php echo $block->getAddToCartUrl($_item); ?>" method="post"> <div style="float: left;"> <input type="number" ...


4

The attribute thumbnail will give you the filename of the image to use as a thumbnail for the product. There's no constraints on the size of that image though and you're trying to resize the image using the style attribute. If you look through the magento source you'll see that you need to use the image helper to resize it, for instance in app/design/...


4

If you want to display related products of child items instead of the related products of the parent item in a configurable product structure, then Create a new module and override _prepareData function the main block file vendor/magento/module-catalog/Block/Product/ProductList/Related.php Something like protected function _prepareData() { $product = ...


4

By default Related products show in content.aside container, which is render after content container. Both content.aside and content comes in main container, So you can move related product after main container. You can use page.bottom.container for moving, use following code in app/design/frontend/{Package}/{theme}/Magento_Catalog/layout/...


3

The products should not appear in related or upsells if they are already in the cart. The qty that is in the cart is not important in this case. Here is how it works in the Related.php block. Mage_Catalog_Block_Product_List_Related::_prepareData looks like this: protected function _prepareData() { $product = Mage::registry('product'); /* @var $...


3

As John pointed out $this references the block object in Magento itself. All templates are rendered with a block. But I want to give you a little more information: Block types There are two main types of blocks - those that utilize a template and those that do not. All template rendering block types inherit from Mage_Core_Block_Template and all others ...


3

In the context of any given block, $this is defined as the block type so in your theme or module definition layout updates, you would need to update the block type to point to the correct block. <block type="sales/order_info" as="info" name="sales.order.info"></block> This is an example block from the Mage_Sales module so when that blocks ...


3

You name name="catalog.product.related" in your xml and call : <?php echo $this->getChildHtml('related_products') ?> It should be : <?php echo $this->getChildHtml('related') ?> if your xml is formed correctly. You can also give an alias in your xml like : as="related_products" In any case, it needs to be a child of the parent node in the ...


3

After trying to execute the given SQL query in phpmyadmin for a default Magento database, I got the following error: #1054 - Unknown column 'e.name' in 'field list' What this means is that the column name does not exist in the table e which is an alias for the table catalog_product_entity. After taking another look at the SQl query, I can see that you are ...


3

I am guessing that you are using Google Chrome so you might want to try firefox. The upsell, cross sell, and related products tabs are loaded via ajax and due to the way different browsers handle javascript, it doesn't always submit ajax loaded content with the rest of your form. For example, click on the Upsells tab, dont change anything, and then click ...


3

Html file is called from Catalog module. magento2.1/vendor/magento/module-catalog/view/frontend/templates/product/list/items.phtml Related, Upsell and cross sell product display inside detail page are coming from here. Here in top file, $type = $block->getType() getting value of related, upsell,crosssell and based on value dynamic content are loaded in ...


3

To display Swatches along with the product name, thumbnail, etc, just like on the Category product lists, I did this in my Theme: Create this file: app/design/frontend/MyCompany/mytheme/Magento_Swatches/layout/catalog_product_view.xml Add this content (almost the same as the catalog_category_view one), so the Swatch renderer template is available on the ...


3

You can create same controller as default addToCart controller. public function execute() { $currentStore = $this->storeManager->getStore(); $baseUrl = $currentStore->getBaseUrl(); $post = $this->getRequest()->getPostValue(); $option=array(); foreach($post as $key => $val) { if($...


3

I was able to fix this: First check the following tables in your DB: catalog_product_link_attribute and catalog_product_link_type If those are empty, you need to run the following SQL queries: INSERT INTO `catalog_product_link_attribute` (`product_link_attribute_id`, `link_type_id`, `product_link_attribute_code`, `data_type`) VALUES (1, 1, 'position', '...


2

Try changing: <?php echo $att->getAttributeId() ?> to: <?php if (is_object($att)) echo $att->getAttributeId() ?>


2

This is doable, but it requires a lot of work. You should ask yourself if is is worth the effort ;) I do, sometimes. You need to ensure all the selectable options are unique. As was mentioned in the answer by @fschmengler you also need to make the forms unique, but I had later found it is best to not use forms, but some javascript that build the form, using ...


2

It seams that you have an extension for adding products to cart via AJAX. This means your addAction from the cart controller is rewritten. Either disable the extension or find out the js function that should be called when adding a product to cart and apply it to the related products add to cart button. That function should handle the AJAX response and ...


2

Try this: Way 1: $collection = Mage::getModel('catalog/product') ->getCollection() ->addAttributeToSelect('*') ->joinField('qty', 'cataloginventory/stock_item', 'qty', 'product_id=entity_id', '{{table}}.stock_id=1', 'left') ->...


2

Don't reinvent the wheel, code for loading the related products already exists in the core. There is a block that shows related products and in the default themes you don't even need to do anything to show it. If it is missing in your theme, you can add this to your theme's layout XML: <reference name="product.info"> <block type="catalog/...


2

This defines the Resave_Products class but does not do anything. Add the following at the bottom: $shell = new Resave_Products(); $shell->run(); If you have a look at the other files in /shell you will see the same.


Only top voted, non community-wiki answers of a minimum length are eligible