Jump to content

[SOLVED] errors adding custom features


Recommended Posts

Hi guys,

 

need a little bit of help here. I don't really know why but for some reason i keep getting this error when i'm adding customized values to features:

 

Fatal error: Call to undefined method ObjectModel::addFeaturesToDB() in /home/mobilhaz/public_html/mobilnew/classes/Product.php on line 3299

 

any ideeas on how to fix this?

 

Thank you.

Link to comment
Share on other sites

Hi guys,

 

need a little bit of help here. I don't really know why but for some reason i keep getting this error when i'm adding customized values to features:

 

Fatal error: Call to undefined method ObjectModel::addFeaturesToDB() in /home/mobilhaz/public_html/mobilnew/classes/Product.php on line 3299

 

any ideeas on how to fix this?

 

Thank you.

 

Hi, thanks for the message. What version of PrestaShop are you using? Have you read the documentation on Attributes, Values and Features? http://doc.prestashop.com/display/PS16/Managing+Product+Features

 

Are you sure you wanted to add features, and not attributes? 

Link to comment
Share on other sites

Solved,

 

The problem was some modification i've made in order to accept multipple values for the features.

 

The corect code if anyone needs it is this (in classes/product.php):

public function addFeaturesToDB($id_feature, $id_value, $cust = 0)
	{
    // Default behavior.
    if ($cust)
		{
			$row = array('id_feature' => (int)$id_feature, 'custom' => 1);
			Db::getInstance()->insert('feature_value', $row);
			$id_value = Db::getInstance()->Insert_ID();
		}

    // For multi-value features, build array of rows and insert into db.
    $base =  array(
      'id_feature' => (int)$id_feature,
      'id_product' => (int)$this->id,
    );
    $rows = array();
    foreach ($id_value as $value) {
      if(!empty($value)) {
        $rows[] = $base + array('id_feature_value' => $value);
      }
    }
    $row = array('id_feature' => (int)$id_feature, 'id_product' => (int)$this->id, 'id_feature_value' => (int)$id_value);
		Db::getInstance()->insert('feature_product', $row);
		SpecificPriceRule::applyAllRules(array((int)$this->id));
		if ($id_value)
			return ($id_value);
	}
Link to comment
Share on other sites

 

Solved,

 

The problem was some modification i've made in order to accept multipple values for the features.

 

The corect code if anyone needs it is this (in classes/product.php):

public function addFeaturesToDB($id_feature, $id_value, $cust = 0)
	{
    // Default behavior.
    if ($cust)
		{
			$row = array('id_feature' => (int)$id_feature, 'custom' => 1);
			Db::getInstance()->insert('feature_value', $row);
			$id_value = Db::getInstance()->Insert_ID();
		}

    // For multi-value features, build array of rows and insert into db.
    $base =  array(
      'id_feature' => (int)$id_feature,
      'id_product' => (int)$this->id,
    );
    $rows = array();
    foreach ($id_value as $value) {
      if(!empty($value)) {
        $rows[] = $base + array('id_feature_value' => $value);
      }
    }
    $row = array('id_feature' => (int)$id_feature, 'id_product' => (int)$this->id, 'id_feature_value' => (int)$id_value);
		Db::getInstance()->insert('feature_product', $row);
		SpecificPriceRule::applyAllRules(array((int)$this->id));
		if ($id_value)
			return ($id_value);
	}

Is this code a core modification to accept multiple features? Could you give an example for other members of the community. Thanks!

Link to comment
Share on other sites

×
×
  • Create New...