Hi - a client is interested in having different images for each subproduct displayed in the cart. I can attach images to the subproduct nodes and get at them in the cart no problem.

Couple questions came up I wasn't sure about:
1) When is a subproduct deleted & recreated? If they go add images to all the subproducts, I wouldn't want them to get wiped out if a change was made to a parent product. Or at least let them know what would trigger that.

2) I believe new variants are only being created when added to the basket - is it possible to run a "create all" function? Or is that what cron is doing?

Thanks a lot, great module.
-Greg

Comments

brmassa’s picture

Assigned: Unassigned » brmassa
Status: Active » Fixed

Greg,

thanks for reporting. lets go:
1* if you use a module like image.module directly on parent product, it will probably give you trouble when you delete/recrete the subproduct. its because image.module believes the image is only linked to one product (i reported this to the dev team but they refused to correct this, claming its a subproduct module problem). delete/recreate WONT change any attribute data, so any image attached to attributes will remain ok. To attach images to parent products, use modules like Slideshow creator or some other filter on body.

2* I once wrote a cron function to create some subproducts on cron but i found two problems: to avoid a huge overload, it should create only a few number of subproducts per cron, however, it was very complex to store a array telling "how many subproducts it was created already". The second problem was on editing the parent product/attribute: instead updating all existing subproduct, which is a HUGEEEE server overload (many times getting PHP timeout) i design to delete all of them. but on product with hundreds subproducts, even deleting was getting problems. Bottom line, i removed the cron feature.

cheers,

massa

Anonymous’s picture

Hey Massa - thanks, as always.

I am using node_images, great way to handle product images. What I am noticing though is if I update the parent product in any way on the current version of ec_live, the subproducts (if there are any) get deleted. And then next time they are added to the cart they get created again with new node ID's. Reading your response above, sounds like it shouldn't work this way? Basically they want to go edit the subproduct nodes after they are all created, but still make updates to the parent products when needed - looking for the best way to do that.

Thanks for the background on "create all"

These clients have also requested a couple nice features I can't do -- adding support for checkboxes, and adding a qty field (that updates price still) to the product page. Could pay you to hammer these out if you're interested in bidding on some side work. Hit my contact page if so.

Thanks!~-greg

Anonymous’s picture

One more point, not sure I was clear - they are trying to have different images used for each of the product variants, not the parent image. Then in the cart they show a little thumbnail of the subproduct/image combo. Makes for a nice cart, but is a pita...

brmassa’s picture

Greg,

* about "delete when editing the parent product and recreate with another Node ID" -> its the way it works. im planning a way to preserve the subproducts, but not for now
* about "checkbox option" -> im going to add this feature on eCommerce Subproducts 4. its already on my postponed list.
* about "quantity field" -> i didnt get it. what about the quantity? like multiple RAM memories on your customizable computer?
* about the pictures -> as i said, you can and should add images to attributes individually, but not to create a combined image like "cotton-black-shirt.png" on selecting the cotton and black attributes from a shirt.

regards,

massa

Anonymous’s picture

Status: Fixed » Closed (fixed)
reg’s picture

Status: Closed (fixed) » Needs work

While we are waiting for ec4 I would like to offer this interim measure for us ec3 users of Live Subproducts.

Be warned, this is just an interim solution and is by no means perfect. Mainly, if you change the options so that currently created pages are no longer valid, it will not delete the no longer valid pages, you have do that yourself one at a time. Also, it does not follow the restrictions of the attributes. If someone wants to add that on, please do so. You would modify the logic in the routine ec_live_subproducts_restrict_options which you will see is currently very basic.

What this does do is the following:
- Disabled the deleting of product variations just because you alter the parent product.
- Adds a button "Submit & Create Variations" - Creates all not yet created variations
- Adds a button "Submit & Remove Variations" - Removes all variations

Much more could be done but please don't ask me for it. This is just a temporary minimal enhancement while waiting to go to ec4 which everyone in ecommerce is pushing.

I haven't created a patch however posted below are the routines that I altered and added. All you have to do is update them in the ec_live_subprdoucts module.

I hope this helps a few other people.

Here is the version I modified:

// $Id: ec_live_subproducts.module,v 1.1.1.2.2.5.2.14 2007/06/14 02:56:19 brmassa Exp $

Here are the routines that I modified and added:

Add this routine:

/**
 * This is quick and dirty. Ideally it should follow the rules set in attribute but since
 * ec4 has so much activity with the promise of much more subproduct functionality, this 
 * will do for now. 
 *
 * Since this restrict combinations to at least one attribute of each variation for a given 
 * product, if you don't want a variation create an option like "No Color" or "None" etc.
 * for now.
 */
function ec_live_subproducts_restrict_options($optionSets, $count) {
	$allowed = array();
	foreach ($optionSets AS $key => $optionSet)
		if (count($optionSet) >= $count)
			$allowed[$key] = $optionSet;
	return $allowed;
}

Replace this routine with below:


/**
 * Find all the combinations of a given set of arrays.
 *
 * This helper function is used to generate all the possible combinations
 * of a set of attributes. In this way, we generate lists of subproducts.
 *
 */
function ec_live_subproducts_combine($optSets, $prepend = array()) {
	if (empty($optSets)) return $optSets;
	
	$combinations = array();
	$currentSetKey = key($optSets);
 	$currentSet[$currentSetKey] = $optSets[$currentSetKey];
	$remainingSets =  array_diff_key($optSets, $currentSet);
 	
	foreach ($currentSet[$currentSetKey] AS $option) {
		$combination = $prepend;
		$combination[$currentSetKey] = $option;
		$combinations[] = $combination;
		if (!empty($remainingSets)) {
			$newCombinations = ec_live_subproducts_combine($remainingSets, $combination);
			if (!empty($newCombinations))
				$combinations = array_merge($combinations, $newCombinations);
		}
  }
	return $combinations;
} // ec_live_subproducts_combine

Note, I am only showing the part to add into the routine below. DO NOT replace your entire ec_live_subproducts_pproduct_attributes with below. insert the code in the code block below, after the code:

$form["submit"] = array(
"#type" => "submit",
"#value" => t("Submit")
);

and above the code:

$header = array( t("Parent Product"), t("Subproducts"));
$output = theme('table', $header, $rows);

return $form;

in the ec_live_subproducts_pproduct_attributes routine. The above three lines are the last lines in the routine/function.


/**
 *
 */
function ec_live_subproducts_pproduct_attributes() {
...
...
...
  $form["create"] = array(
    "#type"   => "submit",
    "#value"  => t("Submit & Create Variations")
  );
  $form["remove"] = array(
    "#type"   => "submit",
    "#value"  => t("Submit & Remove Variations")
  );
	
  # Create any combinations not yet created
  switch ($_POST['op']) {
  	case 'Submit & Create Variations':
			if ($pproducts = ec_live_subproducts_pproduct_get(arg(1))) {
	      $pproduct = $pproducts[arg(1)];
				$options = array();
	      foreach ($pproduct->pproduct_attributes AS $attribute) {
		      $options[$attribute["tid"]][] = $attribute["nid"];
				}
				if (!empty($options)) {
					$combinations = ec_live_subproducts_combine($options);
					$combinations = ec_live_subproducts_restrict_options($combinations, count($pproduct->pproduct_attributes));
					foreach ($combinations as $combination)
						$new_node = ec_live_subproducts_subproduct_set($pproduct, $combination, TRUE);
				}
			}
			break;
		
		case 'Submit & Remove Variations':
			if ($pproducts = ec_live_subproducts_pproduct_get(arg(1))) {
	      $pproduct = $pproducts[arg(1)];
			  if (empty($pproduct->pparent) and $nodes = db_query("SELECT nid FROM {ec_product} WHERE pparent = %d ", $node->nid))
	        while ($product = db_fetch_object($nodes))
	          node_delete($product->nid);
	    }
			break;
		
		default:
	}
...
...
...
} // ec_live_subproducts_pproduct_attributes

Note, I am only showing the case statement below that I commented out. DO NOT replace your entire ec_live_subproducts_nodeapi with below. ONLY comment out the code under -- case "update": -- as shown below.


/**
 * Implementation of hook_nodeapi().
 *
 * Modify the nodes aperance, loading and saving processes
 */
function ec_live_subproducts_nodeapi(&$node, $op, $arg) {
...
...
...
		case "update":
/*
		  if (empty($node->pparent) and $nodes = db_query("SELECT nid FROM {ec_product} WHERE pparent = %d ", $node->nid)) {
        while ($product = db_fetch_object($nodes)) {
          node_delete($product->nid);
        }
      }
*/
      break;
...
...
...
    

I also removed the cron routine as it called the combine routine which has been completely rewritten and was disabled anyway.

reg’s picture

Oops, I slipped up - here is the ec_live_subproducts_pproduct_attributes() function again with a minor needed fix. The same instructions apply as prefixing this function above. I.e.: don't replace the entire function, just insert the code below in the appropriate place.

/**
*
*/
function ec_live_subproducts_pproduct_attributes() {
...
...
...
  $form["create"] = array(
    "#type"   => "submit",
    "#value"  => t("Submit & Create Variations")
  );
  $form["remove"] = array(
    "#type"   => "submit",
    "#value"  => t("Submit & Remove Variations")
  );
	
  # Create any combinations not yet created
  switch ($_POST['op']) {
  	case 'Submit & Create Variations':
			if ($pproducts = ec_live_subproducts_pproduct_get(arg(1))) {
	      $pproduct = $pproducts[arg(1)];
				$options = array();
	      foreach ($pproduct->pproduct_attributes AS $attribute) {
		      $options[$attribute["tid"]][] = $attribute["nid"];
				}
				if (!empty($options)) {
					$combinations = ec_live_subproducts_combine($options);
					Lg('1','','',$combinations);
					Lg('1','','',$pproduct->pproduct_attributes);
					
					$count=0;
					foreach ($pproduct->pproduct_attributes AS $attribute)
						$optionSets[$attribute['tid']] = 1;
					$combinations = ec_live_subproducts_restrict_options($combinations, count($optionSets));
					foreach ($combinations as $combination)
						$new_node = ec_live_subproducts_subproduct_set($pproduct, $combination, TRUE);
				}
			}
			break;
		
		case 'Submit & Remove Variations':
			if ($pproducts = ec_live_subproducts_pproduct_get(arg(1))) {
	      $pproduct = $pproducts[arg(1)];
			  if (empty($pproduct->pparent) and $nodes = db_query("SELECT nid FROM {ec_product} WHERE pparent = %d ", $node->nid))
	        while ($product = db_fetch_object($nodes))
	          node_delete($product->nid);
	    }
			break;
		
		default:
	}
...
...
...
} // ec_live_subproducts_pproduct_attributes

Although this works for me, it all comes "as is", no guarantees etc.

reg’s picture

Eh, remove the (two) lines that start with "Lg(...". That's my testing code and it will error if you don't. Sorry, it's been a long night.

brmassa’s picture

Status: Needs work » Closed (fixed)

Guys,

im so deeply involved on eC4 that i really dont have the time to support EC LS anymore. if someone provides a patch, i will be glad to use it.

regards,

massa

brmassa’s picture