cancel
Showing results for 
Search instead for 
Did you mean: 

Custom Product Type

SOLVED
   Did you know you can see the translated content as per your choice?

Translation is in progress. Please check again after few minutes.

Custom Product Type

Hey!

I'm trying to create a custom product type, based on Mage Virtual Products and run into a problem setting up my module's configuration file. Through core debugging i found out, that my product type model class is not present in Mage_Core_Model_Config->_classNameCache->global/models. Not like my helper class, what has the same structure in my config file and is loaded in the core config model class name cache.

 

/app/etc/modules/Dan_CouponProduct.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- /**
* Module Initial Configuration
*
* @author: helln
*/ -->

<config>
	<modules>
		<Dan_CouponProduct>
			<active>true</active>
			<codePool>local</codePool>
		</Dan_CouponProduct>
		<depends>
			<Mage_Catalog />
		</depends>
	</modules>
</config>

 

 

 

/app/code/local/Dan/CouponProduct/etc/config.xml

<?xml version="1.0" encoding="UTF-8"?>

<!-- /**
* Module Configuration
*
* @author: helln
*/ -->

<config>
	<modules>
		<Dan_CouponProduct>
			<version>0.0.1</version>
		</Dan_CouponProduct>
	</modules>
	
	<global>
		<catalog>
			<product>
				<type>
					<coupon translate="label" module="dan_couponproduct">
						<label>Coupon Product</label>
						<model>dan_couponproduct/product_type</model>
						<is_qty>1</is_qty>
						<composite>0</composite>
						<can_use_qty_decimals>0</can_use_qty_decimals>
					</coupon>
				</type>
			</product>
		</catalog>
		
		<helpers>
			<dan_couponproduct>
				<class>Dan_CouponProduct_Helper</class>
			</dan_couponproduct>
		</helpers>
		
		<models>
			<dan_couponproduct>
				<class>Dan_CouponProduct_Model</class>
			</dan_couponproduct>
		</models>
	</global>
</config>

 

/app/code/local/Dan/CouponProduct/Model/Product/Type.php

class Dan_CouponProduct_Model_Product_Type extends Mage_Catalog_Model_Product_Type_Virtual {
	const TYPE_COUPON = 'coupon';
	
	protected function _prepareProduct(Varien_Object $buyRequest, $product, $processMode) {
		$tmp = 0;
		return parent::_prepareProduct($buyRequest, $product, $processMode);
	}
}

 

/app/code/local/Dan/CouponProduct/Helper/Data.php

<?php /**
* Helper
*
* @author: helln
*/
class Dan_CouponProduct_Helper_Data extends Mage_Catalog_Helper_Data {
}

 

/app/code/local/Dan/CouponProduct/Model/CouponProduct.php

<?php /**
* Module Model
*
* @author: helln
*/

class Dan_CouponProduct_Model extends Mage_Core_Model_Abstract {
	protected function _construct() {
		$this->_init('dan_couponproduct/couponproduct');
	}
}

 

error
Fatal error: Call to a member function setConfig() on a non-object in /var/www/html/development/cms/magento/1/app/code/core/Mage/Catalog/Model/Product/Type.php on line 80

 

 

 

Next thing what makes me wonder is, that i had to provide a helper class. Shouldn't my module inherit automatically all unprovided classes, from the module named in the "depends" element, in my initial configuration file?
Did i misunderstood that part?

Help would be very appreciated. Smiley Happy

Thanks
Nik

1 ACCEPTED SOLUTION

Accepted Solutions

Re: Custom Product Type

Hi @helln

 

You are pretty close there. Did you define your modules model shorthand (dan_couponproduct)? If not add the following to your modules config file under the global node:

 

 

<models>
    <dan_couponproduct>
        <class>Dan_CouponProduct_Model</class>
    </dan_couponproduct>
</models>

 

The depends function in M1, doesn't do much other then preventing your store from running the module (or the entire store), when a dependency fails.

 

I hope this helps :-)

 

View solution in original post

2 REPLIES 2

Re: Custom Product Type

Hi @helln

 

You are pretty close there. Did you define your modules model shorthand (dan_couponproduct)? If not add the following to your modules config file under the global node:

 

 

<models>
    <dan_couponproduct>
        <class>Dan_CouponProduct_Model</class>
    </dan_couponproduct>
</models>

 

The depends function in M1, doesn't do much other then preventing your store from running the module (or the entire store), when a dependency fails.

 

I hope this helps :-)

 

Re: Custom Product Type

Thanks for your reply @Theis Corfixen!

 

As you suspected correctly i had no model class mentioned in my config.xml
Based on the misunderstandig of the Magento Development Guidelines (v1.0), that all unprovided classes will be inherited from Mage Catalog i made this mistake.
(I will correct and complete my code in the original post, to provide a functional sample of a custom product type)

Thanks again for your assistance!

Kindes Regards
Nik