Magento - Load Only Configurable Products

Magento - load only configurable products

The problem with getLoadedProductCollection() is it's already loaded - the products' data has already been retrieved from the database. Just using the current category's product collection isn't good enough either, that will ignore the "layers" (attribute filters). The trick is to remove the loaded products from the list first.

// First make a copy, otherwise the rest of the page might be affected!
$_productCollection = clone $this->getLoadedProductCollection();
// Unset the current products and filter before loading the next.
$_productCollection->clear()
->addAttributeToFilter('type_id', 'configurable')
->load();

print_r($_productCollection) has it's issues too, you're not just outputting the products but also all details of the resource that is the database connection, and cached values, and the products' individual resources, and so on...

In this case I think you would be happier with:

print_r($_productCollection->toArray())

Magento filter simple and configurable products together

I believe that you're looking for a collection that includes both simple and configurable products.
Use this:

$collection = Mage::getModel('catalog/product')->getCollection()
->addAttributeToFilter('type_id', array('in' => array('simple','configurable')));

Get All simple product from a Configurable Product in Magento Product View

use the following script in

app/design/frontend/default/[your theme]/template/catalog/product/view/type/options/configurable.phtml

Inside the script:

spConfig.getIdOfSelectedProduct = function () {
var existingProducts = new Object();
for (var i = this.settings.length - 1; i >= 0; i--) {
var selected = this.settings[i].options[this.settings[i].selectedIndex];
if (selected.config) {
for (var iproducts = 0; iproducts < selected.config.products.length; iproducts++) {
var usedAsKey = selected.config.products[iproducts] + "";
if (existingProducts[usedAsKey] == undefined) {
existingProducts[usedAsKey] = 1;
} else {
existingProducts[usedAsKey] = existingProducts[usedAsKey] + 1;
}
}
}
}
for (var keyValue in existingProducts) {
for (var keyValueInner in existingProducts) {
if (Number(existingProducts[keyValueInner]) < Number(existingProducts[keyValue])) {
delete existingProducts[keyValueInner];
}
}
}
var sizeOfExistingProducts = 0;
var currentSimpleProductId = "";
for (var keyValue in existingProducts) {
currentSimpleProductId = keyValue;
sizeOfExistingProducts = sizeOfExistingProducts + 1
}
if (sizeOfExistingProducts == 1) {
alert("Selected product is: " + currentSimpleProductId)
}
}

Now add onchange event to your dropdown in same page :

onchange = "spConfig.getIdOfSelectedProduct()"

Full description

Php Magento list all configurable products out with simple products out of stock

Here is a script with which you can find all those configurables that do not have simples with stock. Afterwards you could then use that array of Ids to exclude them in your filter.

<?php
require_once('app/Mage.php');
umask(0);
Mage::app();

$collectionConfigurable = Mage::getResourceModel('catalog/product_collection')->addAttributeToFilter('type_id', array('eq' => 'configurable'));

$outOfStockConfis = array();
foreach ($collectionConfigurable as $_configurableproduct) {
$product = Mage::getModel('catalog/product')->load($_configurableproduct->getId());
if (!$product->getData('is_salable')) {
$outOfStockConfis[] = $product->getId();
}
}

Then use this to remove the configurable products which are not saleable from your collection:

$products->addAttributeToFilter('entity_id',array('nin' => $outOfStockConfis));

magento filter configurable product by child products attribute

$attributeCode = 'color';
$attributeValue = 'Blue';

$attribute = Mage::getSingleton('eav/config')
->getAttribute('catalog_product', $attributeCode);

if ($attribute->usesSource()) {
$options = $attribute->getSource()->getAllOptions(false);
}

$attributeValueId = 0;
foreach ($options as $option) {
if ($option['label'] == $attributeValue) {
$attributeValueId = $option['value'];
}
}

$productId = YOUR_CONFIGURABLE_PRODUCT_ID; // ID of configurable product

$product = Mage::getModel('catalog/product')->load($productId);

$childProducts = Mage::getModel('catalog/product_type_configurable')
->getUsedProductCollection($product)
->addAttributeToSelect('*')
->addAttributeToFilter($attributeCode, $attributeValueId);

Source: Magento: Filter Configurable Product by Child Product’s Attribute



Related Topics



Leave a reply



Submit