Display Product collection issue in Magento 2Remove add to cart button for some productsdisplay product list in product view pagemagento show product collection by idMagento 2: add fields to products collectionMaximum price display first collectionCustom product collection on list.phtml do not outputs price and product nameProduct grid display issueMagento 2 collection loop issueHow to create custom form in Magento 2.2.3List Product Collection into template file in Magento 2
Running a linear programming model to maximize binned predictions
Is it OK to accept a job opportunity while planning on not taking it?
What would be the side effects on the life of a person becoming indestructible?
Can 々 stand for a duplicated kanji with a different reading?
Does a definite integral equal to the Möbius function exist?
Impact of throwing away fruit waste on a peak > 3200 m above a glacier
Found more old paper shares from broken up companies
In a script how can I signal who's winning the argument?
Why is a dedicated QA team member necessary?
How can Kazakhstan perform MITM attacks on all HTTPS traffic?
how to add 1 milliseconds on a datetime string?
Why did computer video outputs go from digital to analog, then back to digital?
Using paddles to support a bug net
Why are angular mometum and angular velocity not necessarily parallel, but linear momentum and linear velocity are always parallel?
How important is a good quality camera for good photography?
Using "Kollege" as "university friend"?
The 50,000 row query limit is not actually a "per APEX call" as widely believed
Are glider winch launches rarer in the USA than in the rest of the world? Why?
Are rockets faster than airplanes?
How can I deal with someone that wants to kill something that isn't supposed to be killed?
Is the apartment I want to rent a scam?
What the purpose of the fuel shutoff valve?
My current job follows "worst practices". How can I talk about my experience in an interview without giving off red flags?
What happens if an IRB mistakenly approves unethical research?
Display Product collection issue in Magento 2
Remove add to cart button for some productsdisplay product list in product view pagemagento show product collection by idMagento 2: add fields to products collectionMaximum price display first collectionCustom product collection on list.phtml do not outputs price and product nameProduct grid display issueMagento 2 collection loop issueHow to create custom form in Magento 2.2.3List Product Collection into template file in Magento 2
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have a product collection and i have used below code to display in my template file as follows.
<ol class="products list items product-items">
<?php
$productCollectionSku = array('111', '222', '333', '444', '555', '666'); // these are the comma separated skus.
foreach($productCollectionSku as $productSku)
$product = $block->getProductBySku($productSku);
$productName = $product->getName();
$shortDescription = $product->getshortDescription();
$productUrl = $product->getProductUrl();
$productId = $product->getId();
$productPrice = $product->getPrice();
$addtoCartUrl = $block->getAddToCartUrlForProduct($productSku);
?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-grid">
<a href="<?php echo $productUrl; ?>" class="product photo product-item-photo">
<span class="product-image-wrapper">
<img class="product-image-photo" src="<?php echo $productImage; ?>" width="240" height="300" alt="<?php echo $productName; ?>"></span>
</a>
<div class="product details product-item-details">
<strong class="product name product-item-name">
<a class="product-item-link" href="<?php echo $productUrl; ?>">
<?php echo $productName; ?></a>
</strong>
<div class="price-box price-final_price">
<span class="price-container price-final_price">
<span class="price-wrapper ">
<span class="price"><?php echo $productPrice; ?></span>
</span>
</span>
</div>
<form action="<?php echo $addtoCartUrl; ?>" method="post" class="best-items">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="productId" value="<?php echo $productId; ?>">
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
</li>
<?php ?>
</ol>
Here is my getProductBysku function
public function getProductBySku($sku)
return $this->productRepository->get($sku);// injecting this class in my block file MagentoCatalogApiProductRepositoryInterface $productRepository,
The above code working fine if all of the SKUs are simple products,
I need to prepare for configurable products also. Can we get the product info
and display here config products with all the variations as swatches.
All I am looking here is how to display configurable products here exactly like in the category list page with the swatches being shown.
Where all the color and size swatches shows with clickable option.
Can anyone help me to implement this one?
Thanks in Advance!!
magento2 product product-collection product-list
This question had a bounty worth +50
reputation from jafar pinjar that ended ended at 2019-07-24 10:25:47Z">18 hours ago. Grace period ends in 5 hours
Looking for an answer drawing from credible and/or official sources.
|
show 9 more comments
I have a product collection and i have used below code to display in my template file as follows.
<ol class="products list items product-items">
<?php
$productCollectionSku = array('111', '222', '333', '444', '555', '666'); // these are the comma separated skus.
foreach($productCollectionSku as $productSku)
$product = $block->getProductBySku($productSku);
$productName = $product->getName();
$shortDescription = $product->getshortDescription();
$productUrl = $product->getProductUrl();
$productId = $product->getId();
$productPrice = $product->getPrice();
$addtoCartUrl = $block->getAddToCartUrlForProduct($productSku);
?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-grid">
<a href="<?php echo $productUrl; ?>" class="product photo product-item-photo">
<span class="product-image-wrapper">
<img class="product-image-photo" src="<?php echo $productImage; ?>" width="240" height="300" alt="<?php echo $productName; ?>"></span>
</a>
<div class="product details product-item-details">
<strong class="product name product-item-name">
<a class="product-item-link" href="<?php echo $productUrl; ?>">
<?php echo $productName; ?></a>
</strong>
<div class="price-box price-final_price">
<span class="price-container price-final_price">
<span class="price-wrapper ">
<span class="price"><?php echo $productPrice; ?></span>
</span>
</span>
</div>
<form action="<?php echo $addtoCartUrl; ?>" method="post" class="best-items">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="productId" value="<?php echo $productId; ?>">
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
</li>
<?php ?>
</ol>
Here is my getProductBysku function
public function getProductBySku($sku)
return $this->productRepository->get($sku);// injecting this class in my block file MagentoCatalogApiProductRepositoryInterface $productRepository,
The above code working fine if all of the SKUs are simple products,
I need to prepare for configurable products also. Can we get the product info
and display here config products with all the variations as swatches.
All I am looking here is how to display configurable products here exactly like in the category list page with the swatches being shown.
Where all the color and size swatches shows with clickable option.
Can anyone help me to implement this one?
Thanks in Advance!!
magento2 product product-collection product-list
This question had a bounty worth +50
reputation from jafar pinjar that ended ended at 2019-07-24 10:25:47Z">18 hours ago. Grace period ends in 5 hours
Looking for an answer drawing from credible and/or official sources.
What is not working / showing exactly? My guess is that only price and the toCartUrl is not working, can you confirm that?
– Arno Vande Cappelle
Jul 15 at 10:28
@ArnoVandeCappelle, If any of the sku in array config product, I need to list that product with all combination selection like in default category list page. where color and size shown.
– jafar pinjar
Jul 15 at 10:30
@ArnoVandeCappelle, Are you clear with it now?
– jafar pinjar
Jul 15 at 10:34
Share your$block->getProductBySku($productSku);
code
– Chirag Patel
Jul 17 at 10:41
@ChiragPatel, I have updated the code
– jafar pinjar
Jul 17 at 10:48
|
show 9 more comments
I have a product collection and i have used below code to display in my template file as follows.
<ol class="products list items product-items">
<?php
$productCollectionSku = array('111', '222', '333', '444', '555', '666'); // these are the comma separated skus.
foreach($productCollectionSku as $productSku)
$product = $block->getProductBySku($productSku);
$productName = $product->getName();
$shortDescription = $product->getshortDescription();
$productUrl = $product->getProductUrl();
$productId = $product->getId();
$productPrice = $product->getPrice();
$addtoCartUrl = $block->getAddToCartUrlForProduct($productSku);
?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-grid">
<a href="<?php echo $productUrl; ?>" class="product photo product-item-photo">
<span class="product-image-wrapper">
<img class="product-image-photo" src="<?php echo $productImage; ?>" width="240" height="300" alt="<?php echo $productName; ?>"></span>
</a>
<div class="product details product-item-details">
<strong class="product name product-item-name">
<a class="product-item-link" href="<?php echo $productUrl; ?>">
<?php echo $productName; ?></a>
</strong>
<div class="price-box price-final_price">
<span class="price-container price-final_price">
<span class="price-wrapper ">
<span class="price"><?php echo $productPrice; ?></span>
</span>
</span>
</div>
<form action="<?php echo $addtoCartUrl; ?>" method="post" class="best-items">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="productId" value="<?php echo $productId; ?>">
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
</li>
<?php ?>
</ol>
Here is my getProductBysku function
public function getProductBySku($sku)
return $this->productRepository->get($sku);// injecting this class in my block file MagentoCatalogApiProductRepositoryInterface $productRepository,
The above code working fine if all of the SKUs are simple products,
I need to prepare for configurable products also. Can we get the product info
and display here config products with all the variations as swatches.
All I am looking here is how to display configurable products here exactly like in the category list page with the swatches being shown.
Where all the color and size swatches shows with clickable option.
Can anyone help me to implement this one?
Thanks in Advance!!
magento2 product product-collection product-list
I have a product collection and i have used below code to display in my template file as follows.
<ol class="products list items product-items">
<?php
$productCollectionSku = array('111', '222', '333', '444', '555', '666'); // these are the comma separated skus.
foreach($productCollectionSku as $productSku)
$product = $block->getProductBySku($productSku);
$productName = $product->getName();
$shortDescription = $product->getshortDescription();
$productUrl = $product->getProductUrl();
$productId = $product->getId();
$productPrice = $product->getPrice();
$addtoCartUrl = $block->getAddToCartUrlForProduct($productSku);
?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-grid">
<a href="<?php echo $productUrl; ?>" class="product photo product-item-photo">
<span class="product-image-wrapper">
<img class="product-image-photo" src="<?php echo $productImage; ?>" width="240" height="300" alt="<?php echo $productName; ?>"></span>
</a>
<div class="product details product-item-details">
<strong class="product name product-item-name">
<a class="product-item-link" href="<?php echo $productUrl; ?>">
<?php echo $productName; ?></a>
</strong>
<div class="price-box price-final_price">
<span class="price-container price-final_price">
<span class="price-wrapper ">
<span class="price"><?php echo $productPrice; ?></span>
</span>
</span>
</div>
<form action="<?php echo $addtoCartUrl; ?>" method="post" class="best-items">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="productId" value="<?php echo $productId; ?>">
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
</li>
<?php ?>
</ol>
Here is my getProductBysku function
public function getProductBySku($sku)
return $this->productRepository->get($sku);// injecting this class in my block file MagentoCatalogApiProductRepositoryInterface $productRepository,
The above code working fine if all of the SKUs are simple products,
I need to prepare for configurable products also. Can we get the product info
and display here config products with all the variations as swatches.
All I am looking here is how to display configurable products here exactly like in the category list page with the swatches being shown.
Where all the color and size swatches shows with clickable option.
Can anyone help me to implement this one?
Thanks in Advance!!
magento2 product product-collection product-list
magento2 product product-collection product-list
edited yesterday
jafar pinjar
asked Jul 15 at 10:25
jafar pinjarjafar pinjar
1,0584 silver badges24 bronze badges
1,0584 silver badges24 bronze badges
This question had a bounty worth +50
reputation from jafar pinjar that ended ended at 2019-07-24 10:25:47Z">18 hours ago. Grace period ends in 5 hours
Looking for an answer drawing from credible and/or official sources.
This question had a bounty worth +50
reputation from jafar pinjar that ended ended at 2019-07-24 10:25:47Z">18 hours ago. Grace period ends in 5 hours
Looking for an answer drawing from credible and/or official sources.
What is not working / showing exactly? My guess is that only price and the toCartUrl is not working, can you confirm that?
– Arno Vande Cappelle
Jul 15 at 10:28
@ArnoVandeCappelle, If any of the sku in array config product, I need to list that product with all combination selection like in default category list page. where color and size shown.
– jafar pinjar
Jul 15 at 10:30
@ArnoVandeCappelle, Are you clear with it now?
– jafar pinjar
Jul 15 at 10:34
Share your$block->getProductBySku($productSku);
code
– Chirag Patel
Jul 17 at 10:41
@ChiragPatel, I have updated the code
– jafar pinjar
Jul 17 at 10:48
|
show 9 more comments
What is not working / showing exactly? My guess is that only price and the toCartUrl is not working, can you confirm that?
– Arno Vande Cappelle
Jul 15 at 10:28
@ArnoVandeCappelle, If any of the sku in array config product, I need to list that product with all combination selection like in default category list page. where color and size shown.
– jafar pinjar
Jul 15 at 10:30
@ArnoVandeCappelle, Are you clear with it now?
– jafar pinjar
Jul 15 at 10:34
Share your$block->getProductBySku($productSku);
code
– Chirag Patel
Jul 17 at 10:41
@ChiragPatel, I have updated the code
– jafar pinjar
Jul 17 at 10:48
What is not working / showing exactly? My guess is that only price and the toCartUrl is not working, can you confirm that?
– Arno Vande Cappelle
Jul 15 at 10:28
What is not working / showing exactly? My guess is that only price and the toCartUrl is not working, can you confirm that?
– Arno Vande Cappelle
Jul 15 at 10:28
@ArnoVandeCappelle, If any of the sku in array config product, I need to list that product with all combination selection like in default category list page. where color and size shown.
– jafar pinjar
Jul 15 at 10:30
@ArnoVandeCappelle, If any of the sku in array config product, I need to list that product with all combination selection like in default category list page. where color and size shown.
– jafar pinjar
Jul 15 at 10:30
@ArnoVandeCappelle, Are you clear with it now?
– jafar pinjar
Jul 15 at 10:34
@ArnoVandeCappelle, Are you clear with it now?
– jafar pinjar
Jul 15 at 10:34
Share your
$block->getProductBySku($productSku);
code– Chirag Patel
Jul 17 at 10:41
Share your
$block->getProductBySku($productSku);
code– Chirag Patel
Jul 17 at 10:41
@ChiragPatel, I have updated the code
– jafar pinjar
Jul 17 at 10:48
@ChiragPatel, I have updated the code
– jafar pinjar
Jul 17 at 10:48
|
show 9 more comments
5 Answers
5
active
oldest
votes
<ol class="products list items product-items">
<?php
$productCollectionSku = array('111', '222', '333', '444', '555', '666'); // these are the comma separated skus.
foreach($productCollectionSku as $productSku)
$product = $block->getProductBySku($productSku);
$productName = $product->getName();
$shortDescription = $product->getshortDescription();
$productUrl = $product->getProductUrl();
$productId = $product->getId();
$productPrice = $product->getPrice();
$addtoCartUrl = $block->getAddToCartUrlForProduct($productSku);
?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-grid">
<a href="<?php echo $productUrl; ?>" class="product photo product-item-photo">
<span class="product-image-wrapper">
<img class="product-image-photo" src="<?php echo $productImage; ?>" width="240" height="300" alt="<?php echo $productName; ?>"></span>
</a>
<div class="product details product-item-details">
<strong class="product name product-item-name">
<a class="product-item-link" href="<?php echo $productUrl; ?>">
<?php echo $productName; ?></a>
</strong>
<div class="price-box price-final_price">
<span class="price-container price-final_price">
<span class="price-wrapper ">
<span class="price"><?php echo $productPrice; ?></span>
</span>
</span>
</div>
<form action="<?php echo $addtoCartUrl; ?>" method="post" class="best-items">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="productId" value="<?php echo $productId; ?>">
$productTypeInstance = $product->getTypeInstance();
$productTypeInstance->setStoreFilter($product->getStoreId(), $product);
if($product->getTypeId() == "configurable"):
$productTypeInstance = $_objectManager->get('MagentoConfigurableProductModelProductTypeConfigurable');
$productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product);
foreach ($productAttributeOptions as $attribute):
$attributeId = $attribute["attribute_id"];
?>
<div class="control">
<span><?=$attribute["label"]?></span>
<select name="super_attribute[<?=$attributeId?>]" id="select_<?=$attributeId?>" class=" required super-attribute-selectadmin__control-select" title="<?=$attribute["label"] ?>" aria-required="true">
<option value="">-- Please Select --</option>
<?php foreach ($attribute["options"] as $attrOption):?>
<option value="<?=$attrOption["value"]?>" ><?= $attrOption["label"]?></option>
<?php endforeach;?>
</select>
</div>
<?php endforeach;?>
<?php endif;?>
<?php
$customOptions = $_objectManager->get('MagentoCatalogModelProductOption')->getProductOptionCollection($product);
foreach ($customOptions as $option):
$optionId = $option->getOptionId();
?>
<div class="control">
<span><?=$option->getTitle()?></span>
<select name="options[<?php echo $optionId?>]" id="select_<?php echo $optionId?>" class=" required product-custom-option admin__control-select" title="<?=$option->getTitle()?>" data-selector="options[<?php echo $optionId?>]" aria-required="true">
<option value="">-- Please Select --</option>
<?php
foreach ($option->getValues() as $value) :
$optionData = $value->getData();
$optionTypeId = $optionData["option_type_id"];
$optionPrice = $optionData["price"];
$optionTitle = $optionData["title"];
?>
<option value="<?=$optionTypeId?>" price="<?= $optionPrice?>"><?= $optionTitle?></option>
<?php endforeach; ?>
</select>
</div>
<?php endforeach;?>
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
</li>
<?php ?>
</ol>
New contributor
hello @Sagar, can you please update me the code for swatches, i am looking for swatches to show over there
– jafar pinjar
yesterday
add a comment |
You can check module-configurable-product
in Magento
You can override configurable.phtml
file to your module.
vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml
As i said in comments, you can check condition like this
$product->getTypeId()=="configurable"
and show your html according to the product.
Hope It helps.
hi @Mohit, is any chance to update as per my collection, I already have product object just need to display it, the above one is not complete answer..
– jafar pinjar
Jul 18 at 8:01
hello @Mohit, can you please brief me how can i use your answer as per my requirement?
– jafar pinjar
2 days ago
I need to show swatches there, the approach u given is for drop downs, Also pls brief me your answer..
– jafar pinjar
2 days ago
you can check in default magento to see how it's working in core magento /var/www/html/magento_226/vendor/magento/module-configurable-product/view/frontend/layout also check themodule-catalog
module
– Mohit Rane
2 days ago
yes i checked over there, that module is for showing option in dropdown but in my case i am using swatches. What code i need to use to make it work like default list page
– jafar pinjar
2 days ago
|
show 2 more comments
Please check with below code to do, get configurable products collection with options.
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$repository = $obj->create('MagentoCatalogModelProductRepository');
$product = $repository->getById('67');
$data = $product->getTypeInstance()->getConfigurableOptions($product);
$options = array();
foreach($data as $attr)
foreach($attr as $p)
$options[$p['sku']][$p['attribute_code']] = $p['option_title'];
foreach($options as $sku =>$d)
$pr = $repository->get($sku);
foreach($d as $k => $v)
echo $k.' - '.$v.' ';
echo ' : '.$pr->getPrice()."n";
hello, @Anas, yes above code will give the options that' fine, if you look into my code that will list collection with all info, same like how can i display in the same template, I am looking exactly for that, I need to fetch all option info if there is config product and display that like in category page, Pls dont share how to get the option info and all, that i can get it. Thanks. Help me to display the config product exactly like in category page, This is what i am looking for..
– jafar pinjar
Jul 18 at 8:43
add a comment |
Try following way...
Create an extension simple and my code add in your helper file after you can get all data in phtml file
<?php
namespace CompanyModuleHelper;
use MagentoCatalogModelResourceModelCategoryCollectionFactory;
class Data extends MagentoFrameworkAppHelperAbstractHelper
/**
* @var MagentoCatalogModelResourceModelProductCollectionFactory
*/
private $productCollection;
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollection
)
parent::__construct($context);
$this->productCollection = $productCollection;
public function getProductCollection()
$productIds = [1,2,3,4];
$collection = $this->productCollection->create()
->addAttributeToSelect('*')
->addStoreFilter()
->addFieldToFilter(
'entity_id',
['in' => $productIds]
);
// sort categories by some value
if ($sortBy)
$collection->addOrderField($sortBy);
// select certain number of categories
if ($pageSize)
$collection->setPageSize($pageSize);
return $collection;
helllo @Rakesh, My question is to display the collection not to get the collection. Already i have collection just i need to display like product list as same like category page
– jafar pinjar
Jul 19 at 13:41
yes but you can add your product id in my collection after you can showing products like listing page
– Rakesh Donga
Jul 19 at 14:27
yes, pls share the code to display collection like category page
– jafar pinjar
Jul 19 at 14:33
add a comment |
You might be able to inject a MagentoSwatchesBlockProductRendererConfigurable
in to your block file (which is responsible for rendering the image/label variations of a product). You can then, in your AbstractBlock::_toHtml()
function add something like so:
$this->configurable->setProduct($this->getProductBySku('my-sku');
$this->setChild('swatches', $this->configurable);
return parent::_toHtml();
You can then output the data of swatches
in your template by using <?= $block->getChildHtml('swatches'); ?>
New contributor
hello @Adam, this i got the idea about this, but of you could update to my question that will be a great help, is it possible to update to my question with the code i used there.
– jafar pinjar
2 days ago
hello @Adam, can you please elaborate?
– jafar pinjar
2 days ago
add a comment |
Your Answer
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "479"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282089%2fdisplay-product-collection-issue-in-magento-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
5 Answers
5
active
oldest
votes
5 Answers
5
active
oldest
votes
active
oldest
votes
active
oldest
votes
<ol class="products list items product-items">
<?php
$productCollectionSku = array('111', '222', '333', '444', '555', '666'); // these are the comma separated skus.
foreach($productCollectionSku as $productSku)
$product = $block->getProductBySku($productSku);
$productName = $product->getName();
$shortDescription = $product->getshortDescription();
$productUrl = $product->getProductUrl();
$productId = $product->getId();
$productPrice = $product->getPrice();
$addtoCartUrl = $block->getAddToCartUrlForProduct($productSku);
?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-grid">
<a href="<?php echo $productUrl; ?>" class="product photo product-item-photo">
<span class="product-image-wrapper">
<img class="product-image-photo" src="<?php echo $productImage; ?>" width="240" height="300" alt="<?php echo $productName; ?>"></span>
</a>
<div class="product details product-item-details">
<strong class="product name product-item-name">
<a class="product-item-link" href="<?php echo $productUrl; ?>">
<?php echo $productName; ?></a>
</strong>
<div class="price-box price-final_price">
<span class="price-container price-final_price">
<span class="price-wrapper ">
<span class="price"><?php echo $productPrice; ?></span>
</span>
</span>
</div>
<form action="<?php echo $addtoCartUrl; ?>" method="post" class="best-items">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="productId" value="<?php echo $productId; ?>">
$productTypeInstance = $product->getTypeInstance();
$productTypeInstance->setStoreFilter($product->getStoreId(), $product);
if($product->getTypeId() == "configurable"):
$productTypeInstance = $_objectManager->get('MagentoConfigurableProductModelProductTypeConfigurable');
$productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product);
foreach ($productAttributeOptions as $attribute):
$attributeId = $attribute["attribute_id"];
?>
<div class="control">
<span><?=$attribute["label"]?></span>
<select name="super_attribute[<?=$attributeId?>]" id="select_<?=$attributeId?>" class=" required super-attribute-selectadmin__control-select" title="<?=$attribute["label"] ?>" aria-required="true">
<option value="">-- Please Select --</option>
<?php foreach ($attribute["options"] as $attrOption):?>
<option value="<?=$attrOption["value"]?>" ><?= $attrOption["label"]?></option>
<?php endforeach;?>
</select>
</div>
<?php endforeach;?>
<?php endif;?>
<?php
$customOptions = $_objectManager->get('MagentoCatalogModelProductOption')->getProductOptionCollection($product);
foreach ($customOptions as $option):
$optionId = $option->getOptionId();
?>
<div class="control">
<span><?=$option->getTitle()?></span>
<select name="options[<?php echo $optionId?>]" id="select_<?php echo $optionId?>" class=" required product-custom-option admin__control-select" title="<?=$option->getTitle()?>" data-selector="options[<?php echo $optionId?>]" aria-required="true">
<option value="">-- Please Select --</option>
<?php
foreach ($option->getValues() as $value) :
$optionData = $value->getData();
$optionTypeId = $optionData["option_type_id"];
$optionPrice = $optionData["price"];
$optionTitle = $optionData["title"];
?>
<option value="<?=$optionTypeId?>" price="<?= $optionPrice?>"><?= $optionTitle?></option>
<?php endforeach; ?>
</select>
</div>
<?php endforeach;?>
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
</li>
<?php ?>
</ol>
New contributor
hello @Sagar, can you please update me the code for swatches, i am looking for swatches to show over there
– jafar pinjar
yesterday
add a comment |
<ol class="products list items product-items">
<?php
$productCollectionSku = array('111', '222', '333', '444', '555', '666'); // these are the comma separated skus.
foreach($productCollectionSku as $productSku)
$product = $block->getProductBySku($productSku);
$productName = $product->getName();
$shortDescription = $product->getshortDescription();
$productUrl = $product->getProductUrl();
$productId = $product->getId();
$productPrice = $product->getPrice();
$addtoCartUrl = $block->getAddToCartUrlForProduct($productSku);
?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-grid">
<a href="<?php echo $productUrl; ?>" class="product photo product-item-photo">
<span class="product-image-wrapper">
<img class="product-image-photo" src="<?php echo $productImage; ?>" width="240" height="300" alt="<?php echo $productName; ?>"></span>
</a>
<div class="product details product-item-details">
<strong class="product name product-item-name">
<a class="product-item-link" href="<?php echo $productUrl; ?>">
<?php echo $productName; ?></a>
</strong>
<div class="price-box price-final_price">
<span class="price-container price-final_price">
<span class="price-wrapper ">
<span class="price"><?php echo $productPrice; ?></span>
</span>
</span>
</div>
<form action="<?php echo $addtoCartUrl; ?>" method="post" class="best-items">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="productId" value="<?php echo $productId; ?>">
$productTypeInstance = $product->getTypeInstance();
$productTypeInstance->setStoreFilter($product->getStoreId(), $product);
if($product->getTypeId() == "configurable"):
$productTypeInstance = $_objectManager->get('MagentoConfigurableProductModelProductTypeConfigurable');
$productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product);
foreach ($productAttributeOptions as $attribute):
$attributeId = $attribute["attribute_id"];
?>
<div class="control">
<span><?=$attribute["label"]?></span>
<select name="super_attribute[<?=$attributeId?>]" id="select_<?=$attributeId?>" class=" required super-attribute-selectadmin__control-select" title="<?=$attribute["label"] ?>" aria-required="true">
<option value="">-- Please Select --</option>
<?php foreach ($attribute["options"] as $attrOption):?>
<option value="<?=$attrOption["value"]?>" ><?= $attrOption["label"]?></option>
<?php endforeach;?>
</select>
</div>
<?php endforeach;?>
<?php endif;?>
<?php
$customOptions = $_objectManager->get('MagentoCatalogModelProductOption')->getProductOptionCollection($product);
foreach ($customOptions as $option):
$optionId = $option->getOptionId();
?>
<div class="control">
<span><?=$option->getTitle()?></span>
<select name="options[<?php echo $optionId?>]" id="select_<?php echo $optionId?>" class=" required product-custom-option admin__control-select" title="<?=$option->getTitle()?>" data-selector="options[<?php echo $optionId?>]" aria-required="true">
<option value="">-- Please Select --</option>
<?php
foreach ($option->getValues() as $value) :
$optionData = $value->getData();
$optionTypeId = $optionData["option_type_id"];
$optionPrice = $optionData["price"];
$optionTitle = $optionData["title"];
?>
<option value="<?=$optionTypeId?>" price="<?= $optionPrice?>"><?= $optionTitle?></option>
<?php endforeach; ?>
</select>
</div>
<?php endforeach;?>
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
</li>
<?php ?>
</ol>
New contributor
hello @Sagar, can you please update me the code for swatches, i am looking for swatches to show over there
– jafar pinjar
yesterday
add a comment |
<ol class="products list items product-items">
<?php
$productCollectionSku = array('111', '222', '333', '444', '555', '666'); // these are the comma separated skus.
foreach($productCollectionSku as $productSku)
$product = $block->getProductBySku($productSku);
$productName = $product->getName();
$shortDescription = $product->getshortDescription();
$productUrl = $product->getProductUrl();
$productId = $product->getId();
$productPrice = $product->getPrice();
$addtoCartUrl = $block->getAddToCartUrlForProduct($productSku);
?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-grid">
<a href="<?php echo $productUrl; ?>" class="product photo product-item-photo">
<span class="product-image-wrapper">
<img class="product-image-photo" src="<?php echo $productImage; ?>" width="240" height="300" alt="<?php echo $productName; ?>"></span>
</a>
<div class="product details product-item-details">
<strong class="product name product-item-name">
<a class="product-item-link" href="<?php echo $productUrl; ?>">
<?php echo $productName; ?></a>
</strong>
<div class="price-box price-final_price">
<span class="price-container price-final_price">
<span class="price-wrapper ">
<span class="price"><?php echo $productPrice; ?></span>
</span>
</span>
</div>
<form action="<?php echo $addtoCartUrl; ?>" method="post" class="best-items">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="productId" value="<?php echo $productId; ?>">
$productTypeInstance = $product->getTypeInstance();
$productTypeInstance->setStoreFilter($product->getStoreId(), $product);
if($product->getTypeId() == "configurable"):
$productTypeInstance = $_objectManager->get('MagentoConfigurableProductModelProductTypeConfigurable');
$productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product);
foreach ($productAttributeOptions as $attribute):
$attributeId = $attribute["attribute_id"];
?>
<div class="control">
<span><?=$attribute["label"]?></span>
<select name="super_attribute[<?=$attributeId?>]" id="select_<?=$attributeId?>" class=" required super-attribute-selectadmin__control-select" title="<?=$attribute["label"] ?>" aria-required="true">
<option value="">-- Please Select --</option>
<?php foreach ($attribute["options"] as $attrOption):?>
<option value="<?=$attrOption["value"]?>" ><?= $attrOption["label"]?></option>
<?php endforeach;?>
</select>
</div>
<?php endforeach;?>
<?php endif;?>
<?php
$customOptions = $_objectManager->get('MagentoCatalogModelProductOption')->getProductOptionCollection($product);
foreach ($customOptions as $option):
$optionId = $option->getOptionId();
?>
<div class="control">
<span><?=$option->getTitle()?></span>
<select name="options[<?php echo $optionId?>]" id="select_<?php echo $optionId?>" class=" required product-custom-option admin__control-select" title="<?=$option->getTitle()?>" data-selector="options[<?php echo $optionId?>]" aria-required="true">
<option value="">-- Please Select --</option>
<?php
foreach ($option->getValues() as $value) :
$optionData = $value->getData();
$optionTypeId = $optionData["option_type_id"];
$optionPrice = $optionData["price"];
$optionTitle = $optionData["title"];
?>
<option value="<?=$optionTypeId?>" price="<?= $optionPrice?>"><?= $optionTitle?></option>
<?php endforeach; ?>
</select>
</div>
<?php endforeach;?>
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
</li>
<?php ?>
</ol>
New contributor
<ol class="products list items product-items">
<?php
$productCollectionSku = array('111', '222', '333', '444', '555', '666'); // these are the comma separated skus.
foreach($productCollectionSku as $productSku)
$product = $block->getProductBySku($productSku);
$productName = $product->getName();
$shortDescription = $product->getshortDescription();
$productUrl = $product->getProductUrl();
$productId = $product->getId();
$productPrice = $product->getPrice();
$addtoCartUrl = $block->getAddToCartUrlForProduct($productSku);
?>
<li class="item product product-item">
<div class="product-item-info" data-container="product-grid">
<a href="<?php echo $productUrl; ?>" class="product photo product-item-photo">
<span class="product-image-wrapper">
<img class="product-image-photo" src="<?php echo $productImage; ?>" width="240" height="300" alt="<?php echo $productName; ?>"></span>
</a>
<div class="product details product-item-details">
<strong class="product name product-item-name">
<a class="product-item-link" href="<?php echo $productUrl; ?>">
<?php echo $productName; ?></a>
</strong>
<div class="price-box price-final_price">
<span class="price-container price-final_price">
<span class="price-wrapper ">
<span class="price"><?php echo $productPrice; ?></span>
</span>
</span>
</div>
<form action="<?php echo $addtoCartUrl; ?>" method="post" class="best-items">
<?php echo $block->getBlockHtml('formkey')?>
<input type="hidden" name="productId" value="<?php echo $productId; ?>">
$productTypeInstance = $product->getTypeInstance();
$productTypeInstance->setStoreFilter($product->getStoreId(), $product);
if($product->getTypeId() == "configurable"):
$productTypeInstance = $_objectManager->get('MagentoConfigurableProductModelProductTypeConfigurable');
$productAttributeOptions = $productTypeInstance->getConfigurableAttributesAsArray($product);
foreach ($productAttributeOptions as $attribute):
$attributeId = $attribute["attribute_id"];
?>
<div class="control">
<span><?=$attribute["label"]?></span>
<select name="super_attribute[<?=$attributeId?>]" id="select_<?=$attributeId?>" class=" required super-attribute-selectadmin__control-select" title="<?=$attribute["label"] ?>" aria-required="true">
<option value="">-- Please Select --</option>
<?php foreach ($attribute["options"] as $attrOption):?>
<option value="<?=$attrOption["value"]?>" ><?= $attrOption["label"]?></option>
<?php endforeach;?>
</select>
</div>
<?php endforeach;?>
<?php endif;?>
<?php
$customOptions = $_objectManager->get('MagentoCatalogModelProductOption')->getProductOptionCollection($product);
foreach ($customOptions as $option):
$optionId = $option->getOptionId();
?>
<div class="control">
<span><?=$option->getTitle()?></span>
<select name="options[<?php echo $optionId?>]" id="select_<?php echo $optionId?>" class=" required product-custom-option admin__control-select" title="<?=$option->getTitle()?>" data-selector="options[<?php echo $optionId?>]" aria-required="true">
<option value="">-- Please Select --</option>
<?php
foreach ($option->getValues() as $value) :
$optionData = $value->getData();
$optionTypeId = $optionData["option_type_id"];
$optionPrice = $optionData["price"];
$optionTitle = $optionData["title"];
?>
<option value="<?=$optionTypeId?>" price="<?= $optionPrice?>"><?= $optionTitle?></option>
<?php endforeach; ?>
</select>
</div>
<?php endforeach;?>
<button type="submit" title="Add to Cart" class="action tocart primary">
<span>Add to Cart</span>
</button>
</form>
</div>
</div>
</li>
<?php ?>
</ol>
New contributor
New contributor
answered 2 days ago
Sagar GaikwadSagar Gaikwad
945 bronze badges
945 bronze badges
New contributor
New contributor
hello @Sagar, can you please update me the code for swatches, i am looking for swatches to show over there
– jafar pinjar
yesterday
add a comment |
hello @Sagar, can you please update me the code for swatches, i am looking for swatches to show over there
– jafar pinjar
yesterday
hello @Sagar, can you please update me the code for swatches, i am looking for swatches to show over there
– jafar pinjar
yesterday
hello @Sagar, can you please update me the code for swatches, i am looking for swatches to show over there
– jafar pinjar
yesterday
add a comment |
You can check module-configurable-product
in Magento
You can override configurable.phtml
file to your module.
vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml
As i said in comments, you can check condition like this
$product->getTypeId()=="configurable"
and show your html according to the product.
Hope It helps.
hi @Mohit, is any chance to update as per my collection, I already have product object just need to display it, the above one is not complete answer..
– jafar pinjar
Jul 18 at 8:01
hello @Mohit, can you please brief me how can i use your answer as per my requirement?
– jafar pinjar
2 days ago
I need to show swatches there, the approach u given is for drop downs, Also pls brief me your answer..
– jafar pinjar
2 days ago
you can check in default magento to see how it's working in core magento /var/www/html/magento_226/vendor/magento/module-configurable-product/view/frontend/layout also check themodule-catalog
module
– Mohit Rane
2 days ago
yes i checked over there, that module is for showing option in dropdown but in my case i am using swatches. What code i need to use to make it work like default list page
– jafar pinjar
2 days ago
|
show 2 more comments
You can check module-configurable-product
in Magento
You can override configurable.phtml
file to your module.
vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml
As i said in comments, you can check condition like this
$product->getTypeId()=="configurable"
and show your html according to the product.
Hope It helps.
hi @Mohit, is any chance to update as per my collection, I already have product object just need to display it, the above one is not complete answer..
– jafar pinjar
Jul 18 at 8:01
hello @Mohit, can you please brief me how can i use your answer as per my requirement?
– jafar pinjar
2 days ago
I need to show swatches there, the approach u given is for drop downs, Also pls brief me your answer..
– jafar pinjar
2 days ago
you can check in default magento to see how it's working in core magento /var/www/html/magento_226/vendor/magento/module-configurable-product/view/frontend/layout also check themodule-catalog
module
– Mohit Rane
2 days ago
yes i checked over there, that module is for showing option in dropdown but in my case i am using swatches. What code i need to use to make it work like default list page
– jafar pinjar
2 days ago
|
show 2 more comments
You can check module-configurable-product
in Magento
You can override configurable.phtml
file to your module.
vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml
As i said in comments, you can check condition like this
$product->getTypeId()=="configurable"
and show your html according to the product.
Hope It helps.
You can check module-configurable-product
in Magento
You can override configurable.phtml
file to your module.
vendor/magento/module-configurable-product/view/frontend/templates/product/view/type/options/configurable.phtml
As i said in comments, you can check condition like this
$product->getTypeId()=="configurable"
and show your html according to the product.
Hope It helps.
edited Jul 18 at 8:15
answered Jul 18 at 7:57
Mohit RaneMohit Rane
87217 bronze badges
87217 bronze badges
hi @Mohit, is any chance to update as per my collection, I already have product object just need to display it, the above one is not complete answer..
– jafar pinjar
Jul 18 at 8:01
hello @Mohit, can you please brief me how can i use your answer as per my requirement?
– jafar pinjar
2 days ago
I need to show swatches there, the approach u given is for drop downs, Also pls brief me your answer..
– jafar pinjar
2 days ago
you can check in default magento to see how it's working in core magento /var/www/html/magento_226/vendor/magento/module-configurable-product/view/frontend/layout also check themodule-catalog
module
– Mohit Rane
2 days ago
yes i checked over there, that module is for showing option in dropdown but in my case i am using swatches. What code i need to use to make it work like default list page
– jafar pinjar
2 days ago
|
show 2 more comments
hi @Mohit, is any chance to update as per my collection, I already have product object just need to display it, the above one is not complete answer..
– jafar pinjar
Jul 18 at 8:01
hello @Mohit, can you please brief me how can i use your answer as per my requirement?
– jafar pinjar
2 days ago
I need to show swatches there, the approach u given is for drop downs, Also pls brief me your answer..
– jafar pinjar
2 days ago
you can check in default magento to see how it's working in core magento /var/www/html/magento_226/vendor/magento/module-configurable-product/view/frontend/layout also check themodule-catalog
module
– Mohit Rane
2 days ago
yes i checked over there, that module is for showing option in dropdown but in my case i am using swatches. What code i need to use to make it work like default list page
– jafar pinjar
2 days ago
hi @Mohit, is any chance to update as per my collection, I already have product object just need to display it, the above one is not complete answer..
– jafar pinjar
Jul 18 at 8:01
hi @Mohit, is any chance to update as per my collection, I already have product object just need to display it, the above one is not complete answer..
– jafar pinjar
Jul 18 at 8:01
hello @Mohit, can you please brief me how can i use your answer as per my requirement?
– jafar pinjar
2 days ago
hello @Mohit, can you please brief me how can i use your answer as per my requirement?
– jafar pinjar
2 days ago
I need to show swatches there, the approach u given is for drop downs, Also pls brief me your answer..
– jafar pinjar
2 days ago
I need to show swatches there, the approach u given is for drop downs, Also pls brief me your answer..
– jafar pinjar
2 days ago
you can check in default magento to see how it's working in core magento /var/www/html/magento_226/vendor/magento/module-configurable-product/view/frontend/layout also check the
module-catalog
module– Mohit Rane
2 days ago
you can check in default magento to see how it's working in core magento /var/www/html/magento_226/vendor/magento/module-configurable-product/view/frontend/layout also check the
module-catalog
module– Mohit Rane
2 days ago
yes i checked over there, that module is for showing option in dropdown but in my case i am using swatches. What code i need to use to make it work like default list page
– jafar pinjar
2 days ago
yes i checked over there, that module is for showing option in dropdown but in my case i am using swatches. What code i need to use to make it work like default list page
– jafar pinjar
2 days ago
|
show 2 more comments
Please check with below code to do, get configurable products collection with options.
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$repository = $obj->create('MagentoCatalogModelProductRepository');
$product = $repository->getById('67');
$data = $product->getTypeInstance()->getConfigurableOptions($product);
$options = array();
foreach($data as $attr)
foreach($attr as $p)
$options[$p['sku']][$p['attribute_code']] = $p['option_title'];
foreach($options as $sku =>$d)
$pr = $repository->get($sku);
foreach($d as $k => $v)
echo $k.' - '.$v.' ';
echo ' : '.$pr->getPrice()."n";
hello, @Anas, yes above code will give the options that' fine, if you look into my code that will list collection with all info, same like how can i display in the same template, I am looking exactly for that, I need to fetch all option info if there is config product and display that like in category page, Pls dont share how to get the option info and all, that i can get it. Thanks. Help me to display the config product exactly like in category page, This is what i am looking for..
– jafar pinjar
Jul 18 at 8:43
add a comment |
Please check with below code to do, get configurable products collection with options.
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$repository = $obj->create('MagentoCatalogModelProductRepository');
$product = $repository->getById('67');
$data = $product->getTypeInstance()->getConfigurableOptions($product);
$options = array();
foreach($data as $attr)
foreach($attr as $p)
$options[$p['sku']][$p['attribute_code']] = $p['option_title'];
foreach($options as $sku =>$d)
$pr = $repository->get($sku);
foreach($d as $k => $v)
echo $k.' - '.$v.' ';
echo ' : '.$pr->getPrice()."n";
hello, @Anas, yes above code will give the options that' fine, if you look into my code that will list collection with all info, same like how can i display in the same template, I am looking exactly for that, I need to fetch all option info if there is config product and display that like in category page, Pls dont share how to get the option info and all, that i can get it. Thanks. Help me to display the config product exactly like in category page, This is what i am looking for..
– jafar pinjar
Jul 18 at 8:43
add a comment |
Please check with below code to do, get configurable products collection with options.
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$repository = $obj->create('MagentoCatalogModelProductRepository');
$product = $repository->getById('67');
$data = $product->getTypeInstance()->getConfigurableOptions($product);
$options = array();
foreach($data as $attr)
foreach($attr as $p)
$options[$p['sku']][$p['attribute_code']] = $p['option_title'];
foreach($options as $sku =>$d)
$pr = $repository->get($sku);
foreach($d as $k => $v)
echo $k.' - '.$v.' ';
echo ' : '.$pr->getPrice()."n";
Please check with below code to do, get configurable products collection with options.
<?php
use MagentoFrameworkAppBootstrap;
require __DIR__ . '/app/bootstrap.php';
$bootstrap = Bootstrap::create(BP, $_SERVER);
$obj = $bootstrap->getObjectManager();
$state = $obj->get('MagentoFrameworkAppState');
$state->setAreaCode('frontend');
$repository = $obj->create('MagentoCatalogModelProductRepository');
$product = $repository->getById('67');
$data = $product->getTypeInstance()->getConfigurableOptions($product);
$options = array();
foreach($data as $attr)
foreach($attr as $p)
$options[$p['sku']][$p['attribute_code']] = $p['option_title'];
foreach($options as $sku =>$d)
$pr = $repository->get($sku);
foreach($d as $k => $v)
echo $k.' - '.$v.' ';
echo ' : '.$pr->getPrice()."n";
answered Jul 18 at 8:37
Anas MansuriAnas Mansuri
1,0041 silver badge16 bronze badges
1,0041 silver badge16 bronze badges
hello, @Anas, yes above code will give the options that' fine, if you look into my code that will list collection with all info, same like how can i display in the same template, I am looking exactly for that, I need to fetch all option info if there is config product and display that like in category page, Pls dont share how to get the option info and all, that i can get it. Thanks. Help me to display the config product exactly like in category page, This is what i am looking for..
– jafar pinjar
Jul 18 at 8:43
add a comment |
hello, @Anas, yes above code will give the options that' fine, if you look into my code that will list collection with all info, same like how can i display in the same template, I am looking exactly for that, I need to fetch all option info if there is config product and display that like in category page, Pls dont share how to get the option info and all, that i can get it. Thanks. Help me to display the config product exactly like in category page, This is what i am looking for..
– jafar pinjar
Jul 18 at 8:43
hello, @Anas, yes above code will give the options that' fine, if you look into my code that will list collection with all info, same like how can i display in the same template, I am looking exactly for that, I need to fetch all option info if there is config product and display that like in category page, Pls dont share how to get the option info and all, that i can get it. Thanks. Help me to display the config product exactly like in category page, This is what i am looking for..
– jafar pinjar
Jul 18 at 8:43
hello, @Anas, yes above code will give the options that' fine, if you look into my code that will list collection with all info, same like how can i display in the same template, I am looking exactly for that, I need to fetch all option info if there is config product and display that like in category page, Pls dont share how to get the option info and all, that i can get it. Thanks. Help me to display the config product exactly like in category page, This is what i am looking for..
– jafar pinjar
Jul 18 at 8:43
add a comment |
Try following way...
Create an extension simple and my code add in your helper file after you can get all data in phtml file
<?php
namespace CompanyModuleHelper;
use MagentoCatalogModelResourceModelCategoryCollectionFactory;
class Data extends MagentoFrameworkAppHelperAbstractHelper
/**
* @var MagentoCatalogModelResourceModelProductCollectionFactory
*/
private $productCollection;
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollection
)
parent::__construct($context);
$this->productCollection = $productCollection;
public function getProductCollection()
$productIds = [1,2,3,4];
$collection = $this->productCollection->create()
->addAttributeToSelect('*')
->addStoreFilter()
->addFieldToFilter(
'entity_id',
['in' => $productIds]
);
// sort categories by some value
if ($sortBy)
$collection->addOrderField($sortBy);
// select certain number of categories
if ($pageSize)
$collection->setPageSize($pageSize);
return $collection;
helllo @Rakesh, My question is to display the collection not to get the collection. Already i have collection just i need to display like product list as same like category page
– jafar pinjar
Jul 19 at 13:41
yes but you can add your product id in my collection after you can showing products like listing page
– Rakesh Donga
Jul 19 at 14:27
yes, pls share the code to display collection like category page
– jafar pinjar
Jul 19 at 14:33
add a comment |
Try following way...
Create an extension simple and my code add in your helper file after you can get all data in phtml file
<?php
namespace CompanyModuleHelper;
use MagentoCatalogModelResourceModelCategoryCollectionFactory;
class Data extends MagentoFrameworkAppHelperAbstractHelper
/**
* @var MagentoCatalogModelResourceModelProductCollectionFactory
*/
private $productCollection;
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollection
)
parent::__construct($context);
$this->productCollection = $productCollection;
public function getProductCollection()
$productIds = [1,2,3,4];
$collection = $this->productCollection->create()
->addAttributeToSelect('*')
->addStoreFilter()
->addFieldToFilter(
'entity_id',
['in' => $productIds]
);
// sort categories by some value
if ($sortBy)
$collection->addOrderField($sortBy);
// select certain number of categories
if ($pageSize)
$collection->setPageSize($pageSize);
return $collection;
helllo @Rakesh, My question is to display the collection not to get the collection. Already i have collection just i need to display like product list as same like category page
– jafar pinjar
Jul 19 at 13:41
yes but you can add your product id in my collection after you can showing products like listing page
– Rakesh Donga
Jul 19 at 14:27
yes, pls share the code to display collection like category page
– jafar pinjar
Jul 19 at 14:33
add a comment |
Try following way...
Create an extension simple and my code add in your helper file after you can get all data in phtml file
<?php
namespace CompanyModuleHelper;
use MagentoCatalogModelResourceModelCategoryCollectionFactory;
class Data extends MagentoFrameworkAppHelperAbstractHelper
/**
* @var MagentoCatalogModelResourceModelProductCollectionFactory
*/
private $productCollection;
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollection
)
parent::__construct($context);
$this->productCollection = $productCollection;
public function getProductCollection()
$productIds = [1,2,3,4];
$collection = $this->productCollection->create()
->addAttributeToSelect('*')
->addStoreFilter()
->addFieldToFilter(
'entity_id',
['in' => $productIds]
);
// sort categories by some value
if ($sortBy)
$collection->addOrderField($sortBy);
// select certain number of categories
if ($pageSize)
$collection->setPageSize($pageSize);
return $collection;
Try following way...
Create an extension simple and my code add in your helper file after you can get all data in phtml file
<?php
namespace CompanyModuleHelper;
use MagentoCatalogModelResourceModelCategoryCollectionFactory;
class Data extends MagentoFrameworkAppHelperAbstractHelper
/**
* @var MagentoCatalogModelResourceModelProductCollectionFactory
*/
private $productCollection;
public function __construct(
MagentoCatalogModelResourceModelProductCollectionFactory $productCollection
)
parent::__construct($context);
$this->productCollection = $productCollection;
public function getProductCollection()
$productIds = [1,2,3,4];
$collection = $this->productCollection->create()
->addAttributeToSelect('*')
->addStoreFilter()
->addFieldToFilter(
'entity_id',
['in' => $productIds]
);
// sort categories by some value
if ($sortBy)
$collection->addOrderField($sortBy);
// select certain number of categories
if ($pageSize)
$collection->setPageSize($pageSize);
return $collection;
answered Jul 19 at 13:14
Rakesh DongaRakesh Donga
2,8496 silver badges23 bronze badges
2,8496 silver badges23 bronze badges
helllo @Rakesh, My question is to display the collection not to get the collection. Already i have collection just i need to display like product list as same like category page
– jafar pinjar
Jul 19 at 13:41
yes but you can add your product id in my collection after you can showing products like listing page
– Rakesh Donga
Jul 19 at 14:27
yes, pls share the code to display collection like category page
– jafar pinjar
Jul 19 at 14:33
add a comment |
helllo @Rakesh, My question is to display the collection not to get the collection. Already i have collection just i need to display like product list as same like category page
– jafar pinjar
Jul 19 at 13:41
yes but you can add your product id in my collection after you can showing products like listing page
– Rakesh Donga
Jul 19 at 14:27
yes, pls share the code to display collection like category page
– jafar pinjar
Jul 19 at 14:33
helllo @Rakesh, My question is to display the collection not to get the collection. Already i have collection just i need to display like product list as same like category page
– jafar pinjar
Jul 19 at 13:41
helllo @Rakesh, My question is to display the collection not to get the collection. Already i have collection just i need to display like product list as same like category page
– jafar pinjar
Jul 19 at 13:41
yes but you can add your product id in my collection after you can showing products like listing page
– Rakesh Donga
Jul 19 at 14:27
yes but you can add your product id in my collection after you can showing products like listing page
– Rakesh Donga
Jul 19 at 14:27
yes, pls share the code to display collection like category page
– jafar pinjar
Jul 19 at 14:33
yes, pls share the code to display collection like category page
– jafar pinjar
Jul 19 at 14:33
add a comment |
You might be able to inject a MagentoSwatchesBlockProductRendererConfigurable
in to your block file (which is responsible for rendering the image/label variations of a product). You can then, in your AbstractBlock::_toHtml()
function add something like so:
$this->configurable->setProduct($this->getProductBySku('my-sku');
$this->setChild('swatches', $this->configurable);
return parent::_toHtml();
You can then output the data of swatches
in your template by using <?= $block->getChildHtml('swatches'); ?>
New contributor
hello @Adam, this i got the idea about this, but of you could update to my question that will be a great help, is it possible to update to my question with the code i used there.
– jafar pinjar
2 days ago
hello @Adam, can you please elaborate?
– jafar pinjar
2 days ago
add a comment |
You might be able to inject a MagentoSwatchesBlockProductRendererConfigurable
in to your block file (which is responsible for rendering the image/label variations of a product). You can then, in your AbstractBlock::_toHtml()
function add something like so:
$this->configurable->setProduct($this->getProductBySku('my-sku');
$this->setChild('swatches', $this->configurable);
return parent::_toHtml();
You can then output the data of swatches
in your template by using <?= $block->getChildHtml('swatches'); ?>
New contributor
hello @Adam, this i got the idea about this, but of you could update to my question that will be a great help, is it possible to update to my question with the code i used there.
– jafar pinjar
2 days ago
hello @Adam, can you please elaborate?
– jafar pinjar
2 days ago
add a comment |
You might be able to inject a MagentoSwatchesBlockProductRendererConfigurable
in to your block file (which is responsible for rendering the image/label variations of a product). You can then, in your AbstractBlock::_toHtml()
function add something like so:
$this->configurable->setProduct($this->getProductBySku('my-sku');
$this->setChild('swatches', $this->configurable);
return parent::_toHtml();
You can then output the data of swatches
in your template by using <?= $block->getChildHtml('swatches'); ?>
New contributor
You might be able to inject a MagentoSwatchesBlockProductRendererConfigurable
in to your block file (which is responsible for rendering the image/label variations of a product). You can then, in your AbstractBlock::_toHtml()
function add something like so:
$this->configurable->setProduct($this->getProductBySku('my-sku');
$this->setChild('swatches', $this->configurable);
return parent::_toHtml();
You can then output the data of swatches
in your template by using <?= $block->getChildHtml('swatches'); ?>
New contributor
New contributor
answered Jul 19 at 16:00
Adam MellenAdam Mellen
765 bronze badges
765 bronze badges
New contributor
New contributor
hello @Adam, this i got the idea about this, but of you could update to my question that will be a great help, is it possible to update to my question with the code i used there.
– jafar pinjar
2 days ago
hello @Adam, can you please elaborate?
– jafar pinjar
2 days ago
add a comment |
hello @Adam, this i got the idea about this, but of you could update to my question that will be a great help, is it possible to update to my question with the code i used there.
– jafar pinjar
2 days ago
hello @Adam, can you please elaborate?
– jafar pinjar
2 days ago
hello @Adam, this i got the idea about this, but of you could update to my question that will be a great help, is it possible to update to my question with the code i used there.
– jafar pinjar
2 days ago
hello @Adam, this i got the idea about this, but of you could update to my question that will be a great help, is it possible to update to my question with the code i used there.
– jafar pinjar
2 days ago
hello @Adam, can you please elaborate?
– jafar pinjar
2 days ago
hello @Adam, can you please elaborate?
– jafar pinjar
2 days ago
add a comment |
Thanks for contributing an answer to Magento Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f282089%2fdisplay-product-collection-issue-in-magento-2%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
What is not working / showing exactly? My guess is that only price and the toCartUrl is not working, can you confirm that?
– Arno Vande Cappelle
Jul 15 at 10:28
@ArnoVandeCappelle, If any of the sku in array config product, I need to list that product with all combination selection like in default category list page. where color and size shown.
– jafar pinjar
Jul 15 at 10:30
@ArnoVandeCappelle, Are you clear with it now?
– jafar pinjar
Jul 15 at 10:34
Share your
$block->getProductBySku($productSku);
code– Chirag Patel
Jul 17 at 10:41
@ChiragPatel, I have updated the code
– jafar pinjar
Jul 17 at 10:48