Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » E-Commerce Categories

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, biapar, Willr, Ingo, simon_w

Page: 1
Go to End
Author Topic: 2247 Views
  • Nathan Cox
    Avatar
    Community Member
    99 Posts

    E-Commerce Categories Link to this post

    Hi, I'm working on a shop using the e-commerce module that needs products to be in multiple categories at once...I figured the exisiting ProductGroup hierarchy isn't going to work here.

    It says in the e-commerce docs that multiple categories are a "proposed feature", were there any plans about how you would implement it?

  • Willr
    Avatar
    Forum Moderator
    5489 Posts

    Re: E-Commerce Categories Link to this post

    we have done a site that had products in multiple categories. I believe you need to use stageChildren and liveChildren. Read http://doc.silverstripe.com/doku.php?id=recipes:customising-the-hierarchy that gives an overview at least of how it would work

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: E-Commerce Categories Link to this post

    The multi-category support is shown here, it's been deleted in the most recent trunk version as it was buggy.

    http://open.silverstripe.com/changeset/43521

    Sean - what was buggy about it?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: E-Commerce Categories Link to this post

    The multiple categories function was a TreeDropdownField to select multiple parent product categories, which is fine - however, there were multiple methods in there to support it. These methods were relying on a specific version of SilverStripe < 2.0.2, and so it was an intense process getting it working on newer versions.

    I removed the multiple categories support in our first version of ecommerce as much as it was a hack and difficult to fix, but in favour of leaving it out to find a better solution.

    Sean

  • Sam
    Avatar
    Administrator
    679 Posts

    Re: E-Commerce Categories Link to this post

    Can you provide some more specifics? What were the methods in there to support it? What broke in the newer versions of SS?

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: E-Commerce Categories Link to this post

    I would if I could get on http://open.silverstripe.com/ and check the old revisions. ;-)

    EDIT: Seems there's too many connections sometimes, it appears to be working again. I'll post more details here when I find them about the multiple categories support.

    Sean

  • Sean
    Avatar
    Forum Moderator
    921 Posts

    Re: E-Commerce Categories Link to this post

    These snippets of code was what held the multiple parents support together. Somewhere in there, or in TreeMultiselectField itself, it was broken, and so we didn't fix this for the initial 0.5 ecommerce release.

    Sam: Maybe you could take a look at, and attempt to get it working. Keep in mind that it's broken in many subsequent releases of SilverStripe for one reason or another. And some of these methods may be deprecated, and not even required?

    Cheers,
    Sean

    // getCMSFields() on Product.php
    $fields->addFieldToTab("Root.Content.Main", new TreeMultiselectField("Parents", "Product Groups","SiteTree"));

    /**
    * Sets the ParentID for the component set
    * which handles our "multiple parents"
    */
    function setParentID($id) {   
       // if ParentID exists, delete it from the Product_Parents table
       if($parentToDelete = $this->getField('ParentID')){
          $this->Parents()->remove($parentToDelete);
       }
       
       // Add the new parent to the Product_Parents table   
       $parents = $this->Parents();
       $parents->add($id);
       
       // Set the ParentID on the SiteTree object for new and reorganise behaviour
       $this->setField('ParentID', $id);
    }
       
    /**
    * Called when we try and set the Parents() component set
    * by Tree Multiselect Field in the administration.
    */
    function onChangeParents(&$items) {
       // This ensures this product can never be a parent of itself
       if($items){
          foreach($items as $k => $id){
             if($id == $this->ID)
                unset($items[$k]);
          }
       }   
       return true;
    }

    /**
    * Return the classes to appear on this node in the CMS tree.
    * We add 'manyparents' to indicate that this node may appear more than
    * once in the tree.
    */
    function CMSTreeClasses($controller) {
       return parent::CMSTreeClasses($controller) . ' manyparents';
    }

    /**
    * If this object is reorganised in the CMS, we need to update the Parents field,
    * otherwise the order will be messed up when we next press save
    */
    function cmsCleanup_parentChanged() {
       $parents = $this->Parents();
       foreach($parents as $parent) $parentIDs[] = $parent->ID;
       $parentVal = implode(",", $parentIDs);
          
       return parent::cmsCleanup_parentChanged() . " $('Form_EditForm').elements.Parents.treeDropdownField.setValue('$parentVal');";
    }

  • Nicolaas
    Avatar
    Forum Moderator
    213 Posts

    Re: E-Commerce Categories Link to this post

    Hi

    Would it work to just have a "virtual page" in the CMS / I think it is called a redirector page.... So you have the product only in one category and you redirect it...

    Not perfect, but perhaps an easy solution.

    Cheers

    Nicolaas

    2247 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.