Jump to content

Adding Customizations to products via csv import?


bnadauld

Recommended Posts

The only way i can get customization to work is by writing db entries via ps_customization_fieldps_customization_field_lang and even then i have to go into each product (in the back office) and move the required slider and click save. With 500 products ..a laborious job to say the least.

 

Any ideas?

 

 

csv.png

custom.png

  • Like 1
Link to comment
Share on other sites

You can make a simple script, here is what I did

 

$id_categories = [1430]; // can be multiple
	$context = Context::getContext();

	$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->ExecuteS('
		SELECT id_product
		FROM '._DB_PREFIX_.'category_product
		WHERE id_category IN('.implode(',', $id_categories).')');

	if($result)
	{
		foreach ($result as $pr) {
			$product = new Product($pr['id_product'], false, $context->language->id);
			$text_count = 3;
			$product->createLabels(0, $text_count);
			$product->customizable = 1;
			$product->text_fields = 3;

			$product->update();

			$fields = $product->getCustomizationFields();

			$n = 0;
			foreach ($fields[1] as $id => $value) {
				switch ($n) {
					case 0:
						$_POST['label_1_'.(int)$id.'_1'] = 'Associated To';
						break;
					case 1:
						$_POST['label_1_'.(int)$id.'_1'] = 'Sender Name';
						break;
					case 2:
						$_POST['label_1_'.(int)$id.'_1'] = 'Recipient Name';
						break;				
				}
				
				$n++;
			}

			$product->updateLabels();	
		}
	}

Adds customization fields to all products of certain categories

  • Like 1
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...