Jump to:

17452 Posts in 4473 Topics by 1971 members

Archive

SilverStripe Forums » Archive » eCommerce multiple images

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: 2324 Views
  • iculshaw
    Avatar
    Community Member
    13 Posts

    eCommerce multiple images Link to this post

    How would i implement having multiple images for each product in the ecommerce module. I'm looking to have multiple images for each product. Reason i'm asking i know you have to change the

    static $has_one = array(
          'Image' => 'Product_Image'
       );

    to a "has many" but i'm unsure of how images are actually processed within sapphire.

    I've also implemented a javascript zoom image (http://www.mind-projects.it/blog/jqzoom_v10) onto the product image so would also benefit from knowing how i can store both a resized image of the uploaded, plus the original image (to be zoomed)

    Thanks

  • Cy
    Avatar
    Community Member
    11 Posts

    Re: eCommerce multiple images Link to this post

    I believe you'll need to create a new class to manage multiple images. That built-in Image Object only supports one.

    This thread has proven helpful to me as regards to multiple images on a page.

    Hope that helps!

  • iculshaw
    Avatar
    Community Member
    13 Posts

    Re: eCommerce multiple images Link to this post

    Ok, i've implemented that ImageAttachment class directly to the Product page and got it workin how i want... however; i have dropped the has_one Image that Product has for each one, and now i need the first of my multiple images to be shown on the front of the product category (e.g. in featured products and nested product groups). I'll post my code below, hopefully someone can help me fathom my way through into getting to the object through all the has ones and has many's through the ecommerce module.

    <?php
    class ImageAttachment extends DataObject {
       static $db = array(
          'Name' => 'Text'
       );
       static $has_one = array(
          'Image' => 'Resize_Image',
          'Product' => 'Product'
       );
       
       static $field_names = array('Name' => 'Name');
       
       function getCMSFields_forPopup() {
          $fields = new FieldSet();
          $fields->push(new TextField('Name', 'Name'));
          $fields->push(new ImageField('Image', 'Image'));
       
          return $fields;
       }
       
    }

    class Resize_Image extends Image {
       static $db = null;

       function generateThumbnail($gd) {
          $gd->setQuality(80);
          return $gd->paddedResize(140,100);
       }
       
       function generateContentImage($gd) {
          $gd->setQuality(90);
          return $gd->resizeByWidth(200);
       }
       
       function generateLargeImage($gd) {
          $gd->setQuality(90);
          return $gd->resizeByWidth(600);
       }
       
    }
    ?>

    My Modified Product class

    /**
        * Image Support
        */
       static $has_one = array(
          'ImageThumbnail' => 'Product_Image',
          'Image' => 'Image'
       );
       
       static $has_many = array(
          'ImageAttachments' => 'ImageAttachment'
       );
       
       static $defaults = array(
          'AllowPurchase' => true
       );
       
       /**
        * Create the fields for a product within the CMS
        */
       function getCMSFields() {
          $fields = parent::getCMSFields();

                // standard extra fields like weight and price
          $fields->addFieldToTab("Root.Content.Main", new TextField("Weight", "Weight (kg)", "", 12));
          $fields->addFieldToTab("Root.Content.Main", new TextField("Price", "Price", "", 12));
          $fields->addFieldToTab("Root.Content.Main", new TextField("Model", "Author", "", 50));

          $fields->addFieldToTab("Root.Content.Main", new TextField("InternalItemID","Product Code","",7));

          $imagetable = new ComplexTableField(
             $this,
             'ImageAttachments', // relation name
             'ImageAttachment', // object class
             ImageAttachment::$field_names, // fields to show in table
             ImageAttachment::getCMSFields_forPopup(), // form that pops up for edit
             "ProductID = {$this->ID}", // a filter to only display item associated with this page
             "Name ASC" // Sort by name
          );
          
          $fields->addFieldToTab('Root.Content.Additional Images', $imagetable);

    ...

       function ImageAttachment() {
          if($obj = DataObject::get('ImageAttachment', "ProductID = $this->ID")) {
             return $obj;
          } else {
             return false;
          }
       }

  • iculshaw
    Avatar
    Community Member
    13 Posts

    Re: eCommerce multiple images Link to this post

    nevermind i fixed it

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