I'm configuring a magento webshop for one of our clients. They've got colorcodes and due to that I have to set up configurable products. However, before the configurable products are being shown on the webshop I need to select an attribute to assign to it...
Now this is really unhandy if I have to import an entire catalog of +/- 800 products...
I already found the next script to make this automatically but I have no clue where to put it... I've already tried using it in the configurable.php file, didn't work. Please help me out!
foreach($configAttrCodes as $attrCode){
$super_attribute= Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product',$attrCode->code);
$configurableAtt = Mage::getModel('catalog/product_type_configurable_attribute')->setProductAttribute($super_attribute);
$newAttributes[] = array(
'id' => $configurableAtt->getId(),
'label' => $configurableAtt->getLabel(),
'position' => $super_attribute->getPosition(),
'values' => $configurableAtt->getPrices() ? $configProduct->getPrices() : array(),
'attribute_id' => $super_attribute->getId(),
'attribute_code' => $super_attribute->getAttributeCode(),
'frontend_label' => $super_attribute->getFrontend()->getLabel(),
);
echo "test ";
}
echo "test2 ";
if(empty($existingAtt) && !empty($newAttributes)){
$configProduct->setCanSaveConfigurableAttributes(true);
$configProduct->setConfigurableAttributesData($newAttributes);
$configProduct->save();
This script is best used a shell script to assign the config attributes to products. Its not complete thou. I had to add alot to this script, like the ability to feed it product ids, and attribute codes to configure along with the configurable attributes.
Its hard to show you whats missing from it, since you need alot more than just this script to assign the attributes. I run one script that grabs all the ids of the configurable products and then makes a cache file with them. I them use another script to feed those ids to the above script so that it may configure them. So in total, 3 scripts. I then use a shell script to run that process.
This was posted by another user to help point you in the direction you need to be heading, but is no way a standalone script. I can email you my source files for all three scripts and you can reverse them down to see what I did if that helps.
Related
I want to add a new template option for the product filters block.
So far, I have copied the existing original.tpl from:
templates\blocks\product_filters
and put it into:
templates\addons\my_changes\blocks\product_filters
then I've renamed the file to: example.tpl and edited the top line of the file to be:
{** block-description:example **}
This basic process has worked for other blocks but not for this product filters one. The only options available in the template list are 'Original', and 'Horizontal filters'.
Is there something special I need to do to make my new template show up?
Templates available to be used by blocks are defined at schema, which is located at "app/schemas/block_manager/blocks.php" file.
Usually schema contains a path to a directory containing all templates that can be used by a block, like it's done for the "products" block:
'templates' => 'blocks/products',
Which makes block manager search templates at design/themes/[theme name]/templates/blocks/products directory.
Unfortunately, by some reasons the schema of the "product_filters" block is inconsistent compared to other block schemas - it contains the list of a concrete templates to be used:
'templates' => array(
'blocks/product_filters/original.tpl' => array(),
'blocks/product_filters/selected_filters.tpl' => array(),
'blocks/product_filters/horizontal_filters.tpl' => array(),
),
Because of that, no directory scan is being performed at a moment of determining a list of templates available for a block.
This is why the approach you're using worked for other blocks but not for "product_filters".
The solution for you is simple - you should create a "app/addons/my_changes/schemas/block_manager/blocks.post.php" file with the following content:
<?php
$schema['product_filters']['templates'] = 'blocks/product_filters';
return $schema;
After that please clear the cache and make sure that the "my_changes" add-on is installed and enabled.
Thanks for pointing out this problem, we'll fix it in an upcoming releases.
I am trying to listen to the "catalog_product_save_before" and "catalog_product_save_after" events which are correctly triggered when I save individual product from admin interface.
But, these events are not triggered when I use the "update attributes" action for multiple product selections, from the product list grid. Is there any event which is triggered whenever a product attribute is updated ?? I know I need to write different observer function for csv upload but I need the event for grid action "Update attributes"..
Thanks in advance.
Cheers..
Got this to work out!!
I used this event : catalog_product_attribute_update_before
This give an array with changed attributes and product ids :
[attributes_data] => Array
(
[price_markup] => 10
)
[product_ids] => Array
(
[0] => 6
)
[store_id] => 0
Hope this helps ..
Cheers!!!
this might be a vague answer, I am not sure what you try to do with the attribute but maybe have a look into the Mage_Indexer module. Its bit more complex but it listens to all events or at least Magento takes care of notifying it if something is outdated or has changed.
And also if something goes funky with your data, rerunning your indexer should clean up all the data in an ideal world.
How do i remove the Period column from my custom report?
i tried with
unset($this->_columns['period']);
but its not working.
I need to start my columns like order number, order date,subtotal etc etc.
This is loaded by a custom grid of Backend of Magento, you need identify this. To find the custom block you can active backend hints and see what grid are loaded in this section.
You can active backend hints with the next Sql:
UPDATE core_config_data SET scope_id = 0 WHERE path like 'dev/debug/template_hints%';
Execute always in development enviroment. Never in production site
You can see how to active backend hints in this link, http://www.damianculotta.com.ar/2009/07/11/mostrar-phtmls-y-bloques-usados-en-el-skin-de-backend-de-magento/ sorry, this is in spanish, I don´t find this information in english :(
With this you also to know the type of block load in this grid, this is the important date. Next you need create a little module that rewrite this block.
Whit this method you can see that the next dates
Template
adminhtml\default\default\template\widget/grid.phtml
Block
Mage_Adminhtml_Block_Report_Sales_Sales_Grid
in the block you can see the next columm in the construct
$this->addColumn('period', array(
'header' => Mage::helper('sales')->__('Period'),
'index' => 'period',
'width' => 100,
'sortable' => false,
'period_type' => $this->getPeriodType(),
'renderer' => 'adminhtml/report_sales_grid_column_renderer_date',
'totals_label' => Mage::helper('sales')->__('Total'),
'html_decorators' => array('nobr'),
));
You need remove this columm in you custom block, always in separate extension.
If you don´t know how you can rewrite a block, only need said me :P
Hope help you
I'm getting the following error when I hit a configurable product using the saveRow method from /app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php:
[05-Jul-2011 18:12:32] PHP Fatal error: Call to undefined method Mage_Catalog_Model_Product_Type_Simple::getConfigurableAttributesAsArray() in /home/gp/public_html/app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php on line 107
My problem is a little different to others I've come across online perhaps in that I'm calling saveRow() from my own script that is building and maintaining a list of products, downloaded from my supplier by xml feed, in a temporary database before then using magento to add or update them in my site's catalog.
require_once($_SERVER['DOCUMENT_ROOT']."/app/code/local/Mage/Catalog/Model/Convert/Adapter/Productimport.php");
$MageProducts = new Mage_Catalog_Model_Convert_Adapter_Productimport();
...
...
foreach($products as $product) {
$result = $MageProducts->saveRow($product);
}
The first time I hit a configurable product I get this error but if I immediately hit refresh the script runs right past that product and all the way through to the end, passing many simple/configurable product sets on its way, without failing.
Line 107 of ProductImport.php is this line
$cspa = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
For some reason the $product->getTypeInstance is returning Mage_Catalog_Model_Product_Type_Simple but only the first time in a session?!
If I add print_r($product->getTypeInstance()) just before that line I get the following for a configurable product
Mage_Catalog_Model_Product_Type_Simple Object ( [_product:protected] => Mage_Catalog_Model_Product Object ( [_cacheTag:protected] => catalog_product [_eventPrefix:protected] => catalog_product [_eventObject:protected] => product [_canAffectOptions:protected] => [_typeInstance:protected] => Mage_Catalog_Model_Product_Type_Simple Object *RECURSION* [_typeInstanceSingleton:protected] => Mage_Catalog_Model_Product_Type_Configurable Object ( [_usedProductAttributeIds:protected] => _cache_instance_used_product_attribute_ids....
Which is clearly wrong...
I want to be able to use my script through cron, but this error is stopping me from doing that so I desperately need some help to fix - can anyone offer some advice?
Before this:
$product->getTypeInstance()->getConfigurableAttributesAsArray($product);
Check $product->isConfigurable();. If it is, only run:
$product->getTypeInstance()->getConfigurableAttributesAsArray($product);
I know this was asked long back but still for anybody who faces this issue in future. I struggled for a week almost and tried different solution found on internet. At last here we go, the issue was i had a simple product with the same sku as the configurable product i was trying to import.
That's work just for configurable items, so for this, first check if product is configurable with this code:
if($product->isConfigurable()){
$cspa = $product->getTypeInstance()->getConfigurableAttributesAsArray($product);
....
I had a custom utility task that allowed users to choose an image to accompany the gift card notice that is sent to the recipient when a gift card is purchased at the magento run shop. In the template, there is an assortment of variables available so you can customize the email that is sent. However, in order to add the correct image, I need to have access to the gift card sku number since my method for handling this was to simply create many gift cards and apply separate images for each one, then use javascript to swap the sku numbers when the user clicks the images. Simple enough.
In the app/code/core/Enterprise/GiftCard/Model/Observer.php file, the variables are set:
$templateData = array(
'name' => $item->getProductOptionByCode('giftcard_recipient_name'),
'email' => $item->getProductOptionByCode('giftcard_recipient_email'),
'sender_name_with_email' => $sender,
'sender_name' => $senderName,
'gift_message' => $item->getProductOptionByCode('giftcard_message'),
'giftcards' => $codeList->toHtml(),
'balance' => $balance,
'is_multiple_codes' => 1 < $goodCodes,
'store' => $order->getStore(),
'store_name' => $order->getStore()->getName(), // #deprecated after 1.4.0.0-beta1
'is_redeemable' => $isRedeemable,
);
So I could add the product sku to this array and it would be available in the template system. Problem is, I don't know where to trace this back to even know how to get the Sku. I assume it is somehow available in the $item var, but magento has no documentation on this particular case and I can't guess since there is no method for testing. The email script is activated when the card is purchased so I can't just click a "Send test" button to see what comes out in the email that is sent to the user. The preview button dismisses variables.
Anyone happen to know about this? Possibly something like $item->getSku()
Any input helps.
Thanks
That snippet is from the method Enterprise_GiftCard_Model_Observer::generateGiftCardAccounts() which is registered as a handler for sales_order_save_after event. That event is passed the same 'order' object as the "new order placed" emails have. You can experiment by altering that email template and triggering a new email by resending from the order page in admin.
$item->getSku() is almost certainly right.