Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7648067
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:37:10+00:00 2026-05-31T10:37:10+00:00

When a new simple product is added (via CSV or manually) we need to

  • 0

When a new simple product is added (via CSV or manually) we need to check if the appropriate configurable product has been added (where SKU = “item_number-item_colour_code” e.g. BLEA2606B-BK001). If the configurable product exists then associate the simple product. If the configurable product does not exist then create using the data in the simple product AND then associate the simple product.
I found some help from HERE but don’t know how check if configurable product already exists, and if not how to create one.

Here is the script file that I downloaded. Can anybody advice if this will work with my scenario?

EDITED

I have scraped the idea of creating configurable product in import. I am doing it by capturing the catalog_product_save_after event now. Hopefully that will get me somewhere.

EDITED 2

OK, Finally, I have it working. I’m doing it in the observer. I know it slows down the product save process but couldn’t think of any other way. Thats what I’m doing:

public function productSave($observer)
{
    $p = $observer->getProduct();

    $pr = Mage::getModel('catalog/product')->load($p->getId());
    $attributeValue = Mage::getResourceModel('catalog/product')->getAttributeRawValue($pr->getId(), 'size');  //loads attribute option value

    $qtyStock = Mage::getModel('cataloginventory/stock_item')->loadByProduct($pr)->getQty();
    Mage::log('Qty: '.$qtyStock.$pr->getId(), null, 'test.txt');
    if ($pr->getTaxClassId() == '0' || !isset($pr->getTaxClassId)) {
        $taxClass = 'None';
    } elseif ($pr->getTaxClassId() == '2') {
        $taxClass = 'Taxable Goods';
    } elseif ($pr->getTaxClassId() == '4') {
        $taxClass = 'Shipping (not used by AvaTax)';
    } elseif ($pr->getTaxClassId() == '5') {
        $taxClass = 'General';
    }

    $_configSku = $pr->getItemNumber().'-'.$pr->getItemColourCode();
    $category = array();
    $categoryCollection = $pr->getCategoryCollection();
    foreach ($categoryCollection as $cat) {
        $category[] = $cat->getId();
    }

    $_configExist = Mage::getModel('catalog/product')->loadByAttribute('sku',$_configSku);

    if($_configExist && $_configSku != '-') {
        //Mage::log($_configExist, null, 'test.txt');
        //Mage::log($_configSku, null, 'test.txt');
        $new_ids        = array();
        $current_ids    = $_configExist->getTypeInstance()->getUsedProductIds();

        foreach($current_ids as $temp_id)
        {
           $new_ids[] = $temp_id;
        }
    }

    if(!$_configExist && $_configSku != '-') {

        $att_size = Mage::getModel('eav/entity_attribute')->loadByCode('catalog_product','size');
        $att_sizes = $this->__getAttList('size');

        $confProduct = Mage::getModel('catalog/product');
        $confProduct->setAttributeSetId('10');
        $confProduct->setSku($_configSku);
        $confProduct->setTypeId('configurable');
        $confProduct->setName($pr->getName());
        $confProduct->setDescription($pr->getDescription());
        $confProduct->setShortDescription($pr->getShortDescription());
        $confProduct->setCreatedAt(strtotime('now'));
        $confProduct->setPrice($pr->getPrice());
        $confProduct->setStatus(1);
        $confProduct->setVisibility(Mage_Catalog_Model_Product_Visibility::VISIBILITY_BOTH);
        $confProduct->setWebsiteIDs(array(1));
        $confProduct->setStockData(array(
         'is_in_stock' => 1,
         'qty' => 9999
        ));
        $confProduct->setTaxClassId( $taxClass );
        $confProduct->setCategoryIds( $category );

        /* Set Configurable Attributes */
        $confProduct->setConfigurableAttributesData($tmp = array(
          array_merge($att_size->getData(), array('label' => '', 'values' => $size_values))
        ));

        $simpleProducts = array(
          $pr->getId()=>array( 'attribute_id'=>'145', 'label'=>'size', 'value_index'=>$attributeValue, 'is_percent'=>0, 'pricing_value'=>'' )
        );

        /* Set Associated Products */
        $confProduct->setConfigurableProductsData( $simpleProducts );

        //print_r( get_class_methods( $confProduct ) );

        $confProduct->save();
    } 
    elseif ($_configExist && !in_array($pr->getId(), $new_ids)) {
        $new_ids        = array();
        $current_ids    = $_configExist->getTypeInstance()->getUsedProductIds();
        $current_ids[]  = $pr->getId();
        $current_ids    = array_unique($current_ids);

        foreach($current_ids as $temp_id)
        {
            parse_str("position=", $new_ids[$temp_id]);
        }
        Mage::log('inside', null, 'test.txt');
        Mage::log($current_ids, null, 'test.txt');
        $_configExist->setConfigurableProductsData($new_ids)->save();            
    }

All works fine with manual product save/update and import csv (it is slow but works). The only thing is, in configurable product, the Attribute Name field is empty. How to set attribute name there?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:37:12+00:00Added an answer on May 31, 2026 at 10:37 am

    I have found the way. See EDITED 2 section in the question for the solution.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on a new feature for our product, a component of which has
The new ASP.NET routing is great for simple path style URL's but if you
New to Quartz and I am curious on the drawing speeds of simple shapes,
I new with jquery and I can do simple coding with it. and I
Relatively new to rails and trying to model a very simple family tree with
I have a simple query: $query = new WP_Query('showposts=5'); that will obviously display 5
Simple question. I'm new to Clojure. How can I use one file from my
This might be simple but I am new to Oracle. I am using Oracle
Im new to droid programming and i got a simple retrieve image from url
I am making a simple game in order to learn a new language. I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.