Magento Configurable Import CSV - magento

I've got the spreadsheet below...
https://docs.google.com/spreadsheet/pub?key=0AjZAunFJlooudFhaQjZFLWZHTGZRc0dwZUMtel9BNmc&output=html
All of the simple products are uploading fine (I've added one as an example). But the configurable is not 'associating' to the products correctly.
When I go into the back-end of Magento after the import and click on the configurable product it asks me which Attributes I would like to assign against the configurable product.
Does anyone know why I cannot associate the configurable product with the simple products? There's obviously an issue with configurable product on the import.

With this function you can Assign/Unassign (merge) list of simple productids to existing configurable product
private function _attachProductToConfigurable( $_childProduct, $_configurableProduct ) {
$loader = Mage::getResourceModel( 'catalog/product_type_configurable' )->load( $_configurableProduct );
$ids = $_configurableProduct->getTypeInstance()->getUsedProductIds();
$newids = array();
foreach ( $ids as $id ) {
$newids[$id] = 1;
}
$newids[$_childProduct->getId()] = 1;
$loader->saveProducts( $_configurableProduct->getId(), array_keys( $newids ) );
}
Thanks

Related

How to programmatically get option id's and values from configurable product in phtml?

I am modifying phtml code were I have access to
$this which happens to be Mage_Checkout_Block_Cart_Item_Renderer_Configurable class
and
$_item = $this->getItem();
$_product = $_item->getProduct();
where product is a configurable product in a cart.
Based on this I need to get a list of option id (swatches) and their values.
For example, to get specific size option id :
$product = $_item->getProduct();
$idStore = $_item->getOrder()->getStoreId();
$sizeSpecificAttributeCode = 'specific_size';
$sizeAttributeOptionId = $product->getResource()
->getAttributeRawValue($product->getId(), $sizeSpecificAttributeCode,$idStore);
from the same logic you can get the swatches or other options

How to get those customer only who has products in wishlist?

I am using following code to get the customers who are having products in their wishlist
$wishlist = Mage::getModel('wishlist/wishlist')->getCollection();
$wishlistCustomers = array();
foreach($wishlist as $wish)
{
$wishlistCustomers[] = $wish->getCustomerId();
}
print_r($wishlistCustomers);
But it is also giving me the customers who does no have products in the wishlist.
Please suggest
You can use getItemsCount() method of the wishlist model to check if a wishlist has any items in it.
...
foreach($wishlist as $wish)
{
if($wish->getItemsCount() > 0){
$wishlistCustomers[] = $wish->getCustomerId();
}
}
print_r($wishlistCustomers);

Magento - How to check if Cross Sell products exist.

In view.phtml I want to check if the product has any cross sell products associated with it.
I've done the same with related products:
$relatedProductsId=$_product->getRelatedProductIds();
$relatedProducts=array();
$i=0;
foreach($relatedProductsId as $relatedProductId)
{
$relatedProducts[$i] = array(Mage::getModel('catalog/product')- >load($relatedProductId)->getProductUrl(),
Mage::getModel('catalog/product')->load($relatedProductId)->getName(),
Mage::getModel('catalog/product')->load($relatedProductId)->getImageUrl(),
Mage::getModel('catalog/product')->load($relatedProductId)->getFormat()
);
$i++;
}
I'm not sure what the function used is for the Cross Sells products.
Please can someone help.
Did you try
$crossSellProducts = $_product->getCrossSellProducts()
?
It will return an array of cross-sell product objects.

Magento - Get Product SKU's and quantities on order

I have created an event observer on the "sales_order_place_after" event, which fires when the user places an order in Magento's checkout. That event triggers my observer, which needs to get the following information, which is then sent to an external inventory management system.
Information needed: The SKU and quantity of every product on the order
I have included part of my observer model below. I am accessing the order object. I can get all the items in the order, but how do I get the SKU for every product that makes up the order. For example, with a simple product, this is very easy. However, with a bundled or configurable product I do not know how to access the children that make up that bundled product with their SKU's and quantities. That is the info I need for both bundled and configurable products. I need the SKU and quantities of the children that were selected. For the life of me, I can't figure out what method to call to access that information. I wish there was something like: $item->getBundleChildrenSkuQuantity();
$order = $observer->getEvent()->getOrder();
$joomecomPacket = array();
if ($order->getTotalItemCount() > 0) {
$items = $order->getAllItems();
foreach ($items as $item) {
$productType = $item->getProductType();
switch ($productType) {
case 'bundle':
break;
case 'configurable':
default: // simple products
if (isset($joomecomPacket[$item['sku']])) {
$joomecomPacket[$item['sku']] += $item['qty_ordered'];
} else {
$joomecomPacket[$item['sku']] = $item['qty_ordered'];
}
break;
}
}
}
You're missing a break after your configurable case. The default case is executing for configurable products.
Try this:
$items = $order->getAllVisibleItems(); // gives only parent items
foreach ($items as $item){
$childItem = $item->getChildren(); //do something with $cildItem like $childItem->getSku() etc...
}

Magento: Filter Configurable Product by their options

I want to filter some configurable products by attributes that are used to create more instances of that product (size, color etc.). This means those attributes are not directly assigned to the configurable product, but their childs.
I already have a code that filters configurable products by some attributes, but these are all assigned to the main product, and the children inherit that: designer.
$attributes_designers = $this->getRequest()->getParam('designers');
$attributes_colors = $this->getRequest()->getParam('color');
$attributes_sizes = $this->getRequest()->getParam('size');
$currentCategory = Mage::getModel('catalog/layer')->getCurrentCategory();
$_productCollection = $currentCategory->getProductCollection();
if(count($attributes_designers)>0 and !in_array("ALL",$attributes_designers)) {
$_productCollection->addAttributeToFilter('designer',$attributes_designers);
}
if(count($attributes_colors)>0 and !in_array("ALL",$attributes_colors)) {
$_productCollection->addAttributeToFilter('color',$attributes_colors);
}
if(count($attributes_sizes)>0 and !in_array("ALL",$attributes_sizes)) {
$_productCollection->addAttributeToFilter('size_apparel_eu',$attributes_sizes);
}
if(isset($_GET['order'])) $_productCollection->setOrder($this->getRequest()->getParam('order'), $this->getRequest()->getParam('dir'));
$_productCollection->load();
here, the color, and size_apparel_eu, are not working, because those are not directly assigned to the product, but their children.
If I'm understanding you correctly here...You first need to get the child products with something like this:
$_product = $this->getProduct();
$_configurable_model = Mage::getModel('catalog/product_type_configurable');
$_child_products = array();
if ($_product->getTypeId() == 'configurable')
$_child_products = $_configurable_model->getUsedProducts(null, $_product);
Then you can use some sort of loop (foreach is handy)
foreach ($_child_products as $_child_product){
$_child_product->getRequest()->getParam('designers');
}
Or however you need to call those methods to get the child product information.
I hope this was helpful and relevent!

Resources