Jump to content

How to overload twice the class "product.php"?


houin

Recommended Posts

Hello I have create the file Product.php and insert the following code:

<?php

 
 
class Product extends ProductCore
 
    public $rrp;
 
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        self::$definition['fields']['rrp'] = array('type' => self::TYPE_FLOAT, 'validate' => 'isCleanHtml');
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
 
}
 ?> 
Everything works trés well .Par against I need again in overloaded this class " Product.php " and to stick :
 
<?php
 class Product extends ProductCore
{
    public $pointsforts;
 
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
      Product::$definition['fields']['pointsforts'] = array('type' => self::TYPE_HTML, 'lang' => false, 'validate' => 'isString');
      parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
 
}
?>  
 
My new file is now:
 

<?php

 
 
class Product extends ProductCore
 
    public $rrp;
 
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        self::$definition['fields']['rrp'] = array('type' => self::TYPE_FLOAT, 'validate' => 'isCleanHtml');
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
 
}
{
    public $pointsforts;
 
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
      Product::$definition['fields']['pointsforts'] = array('type' => self::TYPE_HTML, 'lang' => false, 'validate' => 'isString');
      parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    }
 
}
?>  
 
Now I have a blank page
 
Help I. Thank you

 

Link to comment
Share on other sites

you cannot have 2 contruct funtions in same class also your curly brackets are wrong, you should do something like this

<?php
class Product extends ProductCore {
 
    public $rrp;
    public $pointsforts;
 
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        self::$definition['fields']['rrp'] = array('type' => self::TYPE_FLOAT, 'validate' => 'isCleanHtml');
	Product::$definition['fields']['pointsforts'] = array('type' => self::TYPE_HTML, 'lang' => false, 'validate' => 'isString');
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    } 

}
?>  

this is not tested, I have just reordered your code.

 

also when you get a blank page usually that means you have errors somwhere, to see what errors you should enable developer mode

Link to comment
Share on other sites

you cannot have 2 contruct funtions in same class also your curly brackets are wrong, you should do something like this

<?php
class Product extends ProductCore {
 
    public $rrp;
    public $pointsforts;
 
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        self::$definition['fields']['rrp'] = array('type' => self::TYPE_FLOAT, 'validate' => 'isCleanHtml');
	Product::$definition['fields']['pointsforts'] = array('type' => self::TYPE_HTML, 'lang' => false, 'validate' => 'isString');
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
    } 

}
?>  

this is not tested, I have just reordered your code.

 

also when you get a blank page usually that means you have errors somwhere, to see what errors you should enable developer mode

Thank you. Everything is OK .

But I would want to add it :

 

<?php
 
class Product extends ProductCore
{
 
 
/**
* Get prices drop
*
* @param integer $id_lang Language id
* @param integer $pageNumber Start from (optional)
* @param integer $nbProducts Number of products to return (optional)
* @param boolean $count Only in order to get total number (optional)
* @return array Prices drop
*/
public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
{
parent::__construct($id_product, $id_lang, $id_shop);
if (!$context)
$context = Context::getContext();
 
if ($full && $this->id)
{
$this->isFullyLoaded = $full;
$this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode)
$this->manufacturer_name = Manufacturer::getNameById((int)$this->id_manufacturer);
$this->supplier_name = Supplier::getNameById((int)$this->id_supplier);
$this->defcat_name = Product::defCat((int)$this->id_category_default); // Ajout pour afficher le nom de la catégorie par defaut du produit
$address = null;
if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null)
$address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
 
$this->tax_rate = $this->getTaxesRate(new Address($address));
 
$this->new = $this->isNew();
 
// keep base price
$this->base_price = $this->price;
 
$this->price = Product::getPriceStatic((int)$this->id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice);
$this->unit_price = ($this->unit_price_ratio != 0  ? $this->price / $this->unit_price_ratio : 0);
if ($this->id)
$this->tags = Tag::getProductTags((int)$this->id);
 
$this->loadStockData();
}
 
if ($this->id_category_default)
$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
}
public function defCat($id_category_default)
{
$category = new Category($id_category_default);
$defcat_name = $category->getName();
return $defcat_name;
}
}
 
 
?> 
Can use me?. Thank you
Link to comment
Share on other sites

I don't get it, what is your pourpose? and what is the problem you have?

It is the suplementaire variable that allows of added the name of the category on the page produces.. I found him  in a tuto. 

I tried him only and she works.Thus I shall like adding her to mas two other variable

But she is can be too long

Thank you

Link to comment
Share on other sites

you want to add more variables with the same method?

 

just add those variables in the construct following the same approach, if it works for 1 variable it will work for more

$this->defcat_name = Product::defCat((int)$this->id_category_default); // Ajout pour afficher le nom de la catégorie par defaut du produit
$this->my_other_variable = "Something here";
$this->my_other_variable2 = "Something else here";

and so on..

Link to comment
Share on other sites

you want to add more variables with the same method?

 

just add those variables in the construct following the same approach, if it works for 1 variable it will work for more

$this->defcat_name = Product::defCat((int)$this->id_category_default); // Ajout pour afficher le nom de la catégorie par defaut du produit
$this->my_other_variable = "Something here";
$this->my_other_variable2 = "Something else here";

and so on..

Yes. But has what is going to re-seem the complete file with my two others variable?

I am one can lost. Thank you

Link to comment
Share on other sites

I think you are using google translate I can't understand anything.. :P  sorry

 

add those 2 lines as you have there and you are done, the complete file is the same with 2 more lines after $this->defcat_name line..

I do not arrive has to make file. Can you make him(it) to me completely. Thank you

Link to comment
Share on other sites


<?php

 

class Product extends ProductCore

{

public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)

{

parent::__construct($id_product, $id_lang, $id_shop);

if (!$context)

$context = Context::getContext();

 

if ($full && $this->id)

{

$this->isFullyLoaded = $full;

$this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode)

$this->manufacturer_name = Manufacturer::getNameById((int)$this->id_manufacturer);

$this->supplier_name = Supplier::getNameById((int)$this->id_supplier);

$this->defcat_name = Product::defCat((int)$this->id_category_default); // Ajout pour afficher le nom de la catégorie par defaut du produit

$this->my_other_variable = "Something here";

$this->my_other_variable2 = "Something else here";

$address = null;

if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null)

$address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};

 

$this->tax_rate = $this->getTaxesRate(new Address($address));

 

$this->new = $this->isNew();

 

// keep base price

$this->base_price = $this->price;

 

$this->price = Product::getPriceStatic((int)$this->id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice);

$this->unit_price = ($this->unit_price_ratio != 0 ? $this->price / $this->unit_price_ratio : 0);

if ($this->id)

$this->tags = Tag::getProductTags((int)$this->id);

 

$this->loadStockData();

}

 

if ($this->id_category_default)

$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);

}

 

public function defCat($id_category_default)

{

$category = new Category($id_category_default);

$defcat_name = $category->getName();

return $defcat_name;

}

}

Link to comment
Share on other sites

<?php 

class Product extends ProductCore
{
	public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
	{
		parent::__construct($id_product, $id_lang, $id_shop);
		if (!$context)
			$context = Context::getContext();
		 
		if ($full && $this->id)
		{
			$this->isFullyLoaded = $full;
			$this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode)
			$this->manufacturer_name = Manufacturer::getNameById((int)$this->id_manufacturer);
			$this->supplier_name = Supplier::getNameById((int)$this->id_supplier);
			$this->defcat_name = Product::defCat((int)$this->id_category_default); // Ajout pour afficher le nom de la catégorie par defaut du produit
			$this->my_other_variable = "Something here";
			$this->my_other_variable2 = "Something else here";
			$address = null;
			if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null)
			$address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
			 
			$this->tax_rate = $this->getTaxesRate(new Address($address));
			 
			$this->new = $this->isNew();
			 
			// keep base price
			$this->base_price = $this->price;
			 
			$this->price = Product::getPriceStatic((int)$this->id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice);
			$this->unit_price = ($this->unit_price_ratio != 0  ? $this->price / $this->unit_price_ratio : 0);
			if ($this->id)
			$this->tags = Tag::getProductTags((int)$this->id);
			 
			$this->loadStockData();
		}
		 
		if ($this->id_category_default)
			$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
	}
	
	public function defCat($id_category_default)
	{
		$category = new Category($id_category_default);
		$defcat_name = $category->getName();
		return $defcat_name;
	}
}

Thank you but I want to put my two variable of the beginning with. And the I do not understand Sorry

Link to comment
Share on other sites

I found the assembly. It is great :

 

<?php
class Product extends ProductCore {
 
    public $rrp;
    public $pointsforts;
 
    public function __construct($id_product = null, $full = false, $id_lang = null, $id_shop = null, Context $context = null)
    {
        self::$definition['fields']['rrp'] = array('type' => self::TYPE_FLOAT, 'validate' => 'isCleanHtml');
Product::$definition['fields']['pointsforts'] = array('type' => self::TYPE_HTML, 'lang' => false, 'validate' => 'isString');
        parent::__construct($id_product, $full, $id_lang, $id_shop, $context);
        if ($full && $this->id)
{
$this->isFullyLoaded = $full;
$this->tax_name = 'deprecated'; // The applicable tax may be BOTH the product one AND the state one (moreover this variable is some deadcode)
$this->manufacturer_name = Manufacturer::getNameById((int)$this->id_manufacturer);
$this->supplier_name = Supplier::getNameById((int)$this->id_supplier);
$this->defcat_name = Product::defCat((int)$this->id_category_default); // Ajout pour afficher le nom de la catégorie par defaut du produit
$this->my_other_variable = "Something here";
$this->my_other_variable2 = "Something else here";
$address = null;
if (is_object($context->cart) && $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')} != null)
$address = $context->cart->{Configuration::get('PS_TAX_ADDRESS_TYPE')};
 
$this->tax_rate = $this->getTaxesRate(new Address($address));
 
$this->new = $this->isNew();
 
// keep base price
$this->base_price = $this->price;
 
$this->price = Product::getPriceStatic((int)$this->id, false, null, 6, null, false, true, 1, false, null, null, null, $this->specificPrice);
$this->unit_price = ($this->unit_price_ratio != 0  ? $this->price / $this->unit_price_ratio : 0);
if ($this->id)
$this->tags = Tag::getProductTags((int)$this->id);
 
$this->loadStockData();
}
 
if ($this->id_category_default)
$this->category = Category::getLinkRewrite((int)$this->id_category_default, (int)$id_lang);
}
 
public function defCat($id_category_default)
{
$category = new Category($id_category_default);
$defcat_name = $category->getName();
return $defcat_name;
    } 
 
}
?>  
Can you validated? Thank you
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...