Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

E-Commerce Modules /

Discuss about the various e-commerce modules available:
Ecommerce, SS Shop, SilverCart and SwipeStripe
Alternatively, have a look the shared mailinglist.

Moderators: martimiz, Nicolaas, Sean, Ed, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba

Product_OrderItem needs to be a subclass of OrderItem


Go to End


2 Posts   1410 Views

Avatar
MonkeyFish

Community Member, 12 Posts

14 March 2011 at 3:13pm

Having a slight issue extending the product class. On each page I have an option to select a header image within the CMS. This method worked well for the Page and ProductGroup classes but wont work with the product class.

mysite/code/NicholsProduct.php:

<?php
class NicholsProduct extends Product {
static $singular_name = 'Nichols Product Page';
static $plural_name = 'Nichols Product Pages';
static $db = array(
);
static $has_one = array(
'HeaderImage' => 'Image'
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main', new ImageField('HeaderImage','Header Image'),'Content');
return $fields;
}

}
class NicholsProduct_Controller extends Product_Controller {
static $singular_name = ' Nichols Product Controller';
static $plural_name = 'Nichols Product Controllers';
}

Completed a flush with no errors. Changed the behavior in the CMS to NicholsProduct now when we go to a product page we get the following error:

[User Warning] NicholsProduct_OrderItem needs to be a subclass of OrderItem
GET /florist/

Line 402 in /home/jasonmoo/public_html/nichols/ecommerce/code/control/ShoppingCart.php
Source

393 static function get_modifiers() {
394 return self::current_order()->Modifiers();
395 }
396
397 /**
398 * Get OrderItem according to product id, and coorresponding parameter filter.
399 */
400 static function get_order_item_by_buyableid($buyableID, $orderItemClassName = "OrderItem", $parameters = null ) {
401 if(!ClassInfo::is_subclass_of($orderItemClassName, "OrderItem")) {
402 user_error("$orderItemClassName needs to be a subclass of OrderItem", E_USER_WARNING);
403 }
404 $filter = self::turn_params_into_sql($parameters = null);
405 $order = self::current_order();
406 $filterString = ($filter && trim($filter) != "") ? " AND $filter" : "";
407 // NOTE: MUST HAVE THE EXACT CLASSNAME !!!!! THEREFORE INCLUDED IN WHERE PHRASE
408 return DataObject::get_one($orderItemClassName, "\"ClassName\" = '".$orderItemClassName."' AND \"OrderID\" = ".$order->ID." AND \"BuyableID\" = ".$buyableID." ". $filterString);

Can some one please point me down the correct path :)

Avatar
MonkeyFish

Community Member, 12 Posts

15 March 2011 at 8:48am

May have resolved the problem by extending the other two classes in product.php and performing another rebuild.

class NicholsProduct_OrderItem extends Product_OrderItem {

}
class NicholsProduct_Image extends Product_Image {

}