Jump to:

2088 Posts in 1007 Topics by 455 members

E-Commerce Modules

SilverStripe Forums » E-Commerce Modules » Product_OrderItem needs to be a subclass of OrderItem

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, frankmullenger, biapar, Willr, Ingo, Jedateach, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1072 Views
  • MonkeyFish
    Avatar
    Community Member
    12 Posts

    Product_OrderItem needs to be a subclass of OrderItem Link to this post

    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

  • MonkeyFish
    Avatar
    Community Member
    12 Posts

    Re: Product_OrderItem needs to be a subclass of OrderItem Link to this post

    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 {
       
    }

    1072 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.