Jump to content

Add New Features Through Feature::addfeatureimport() :s


TheApprentice

Recommended Posts

Hi guys,

 

I'm having trouble with that function on Feature.php class. I'm trying to import new features to my prestashop but always next error is making me crazy:

Fatal error: Uncaught Unknown column 'f.id_product' in 'on clause'

                SELECT DISTINCT p.id_product
                FROM ps_product p
                LEFT JOIN ps_feature f ON (f.id_product = p.id_product)
                WHERE f.id_feature = 453
thrown in /var/www/classes/db/Db.php on line 635

I don't know what I'm doing wrong, i google it looking for a possible bug in my PS version but nothing found (i'm using PS 1.6.0.9).

 

I show you a part of my function:

@ini_set('max_execution_time', 0);
/** No max line limit since the lines can be more than 4096. Performance impact is not significant. */
define('MAX_LINE_SIZE', 0);
/** Used for validatefields diying without user friendly error or not */
define('UNFRIENDLY_ERROR', false);
/** this value set the number of columns visible on each page */
define('MAX_COLUMNS', 6);

define('COLUMNS_SEPARATOR', '#');
define('ELEMENTS_SEPARATOR', ',');

/** correct Mac error on eof */
@ini_set('auto_detect_line_endings', '1');

if (!defined('_PS_VERSION_'))
    exit;

class Importador extends Module {
...
...
...

public function updateProducts()
	{
		$defaultLanguageId = (int) Configuration::get('PS_LANG_DEFAULT');
		self::setLocale();
		
		$local_feed_products = dirname(__FILE__) . "/feed/products.xml";
	
		if (file_exists($local_feed_products)) 
		{
			if ($products = simplexml_load_file($local_feed_products)) 
			{
				//Recorremos cada elemento del xml
				$upd_products = 0;
				$new_products = 0;
				$idsupplier = 0;
				$i = 0;
				foreach ($products->product as $item) 
				{
					...
					...
					
	
					if ($id_product) 
					{
						
						$product = new Product((int) ($id_product), false, $this->context->language->id, $this->context->shop->id);
		
						...
						...
						
						$product->update();
						
						
						// Features import
						if (isset($item->features->feature) && !empty($item->features->feature)) {
							foreach ($item->features->feature as $single_feature) {
								$tab_feature = explode(':', $single_feature);
								$feature_name = trim($tab_feature[0]);
								$feature_value = trim($tab_feature[1]);
								$position = isset($tab_feature[2]) ? $tab_feature[2]: false;
								if(!empty($feature_name) && !empty($feature_value))
								{
									$id_product = (int)$product->id;
									$id_feature = (int)Feature::addFeatureImport($feature_name, $position);
									$id_feature_value = (int)FeatureValue::addFeatureValueImport($id_feature, $feature_value, $id_product, $defaultLanguageId);
									Product::addFeatureProductImport($id_product, $id_feature, $id_feature_value);
									
								}
							}
							
							// clean feature positions to avoid conflict
							Feature::cleanPositions();
						}
					}
					
				}

			} 
			else {
				die('El archivo XML no se ha podido cargar');
				//return false;
			}
		} else {
			die('El archivo XML no existe');
			//return false;
		}
	}
	
}

I know the problem is on the Hook::exec('actionFeatureSave', array('id_feature' => $this->id)); in Feature::update() but i don't know why and exactly where...

 

Can someone help me?

 

Thank you in advance.

Link to comment
Share on other sites

ps_feature doesn't have a id_product column, you need to join your query with ps_feature_product

Thank you for your reply but, as you can see I'm using native classes without overriding them. 

 

I know ps_feature has not id_product field, that's i can't understand and makes me crazy :S

Link to comment
Share on other sites

right, with you know.

 

Have you searched for actionFeatureSave and afterSaveFeature (old hook name) in the code, see if you have a module being called?  I can see blocklayered module get invoked on this hook, but I don't see that making the query you're seeing.

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...