SilverCart Forum

We moderate this Forum and we're here to help. Have you already run a forum search to check if your problem has already been solved?

You can help us helping you by providing detailed error messages, screenshots and logfile entries.

SebastianRamon

Page: 1
Topic Updating CMS 1785 Views

Updating CMS

22 January 2013 at 9:10pm Last edited: 22 January 2013 9:11pm

Hi,

This is probably a simple question to solve, but I have hit a brick wall.

I am adding some fields to Product, which is fine. But when I try and add them to the CMS I get an "Internal Server Error" when looking at an individual product when logged in as Admin:

class SilvercartSetupFeeProduct extends DataObjectDecorator {

/**
* attributes
*
* @var array
*/

   public function extraStatics(){
   return array(
      'db' => array(
    'SetupFee'     => 'Money', //the setup cost per colour/position
    'FinalSetupFee' => 'Money', //the final setup cost per colour/position taking into account the number of colours and positions and MinimumQuantityFee, if any
    'MinimumQuantity'     => 'Int', //the minimum quantity that can be ordered without paying MinimumQuantityFee
    'MinimumQuantityFee' => 'Money', //the fee for ordering less than MinimumQuantity of a product
      )
   );
   }

/**
* Decorates the getCMSFields method and adds variant specific GUI elements.
*
* @param FieldSet &$fields The FieldSet from the decorated object.
*
* @return void
*
* @author Sascha Koehler <skoehler@pixeltricks.de>, Sebastian Diel <sdiel@pixeltricks.de>
* @since 24.05.2012
*/
public function updateCMSFields(FieldSet &$fields) {
if ($this->owner->ID) {
$SetupFeePrice = $fields->dataFieldByName('SetupFee');
$root = $fields->findOrMakeTab('Root');
$root->removeByName('SetupFee');
$fields->addFieldToTab('Root.Main', $SetupFeePrice);
}
}
}

No doubt it is something pretty simple.

Regards,

Graeme

Re: Updating CMS

23 January 2013 at 12:55pm

Hi Graeme,

here's how updateCMSFields and updateScaffoldFormFields should look like if you want to add a money-attribute to a SilvercartProduct:

class SilvercartSetupFeeProduct extends DataObjectDecorator {
public function extraStatics(){

return array(
'db' => array(
'SetupFee' => 'Money', //the setup cost per colour/position
'FinalSetupFee' => 'Money', //the final setup cost per colour/position taking into account the number of colours and positions and MinimumQuantityFee, if any
'MinimumQuantity' => 'Int', //the minimum quantity that can be ordered without paying MinimumQuantityFee
'MinimumQuantityFee' => 'Money', //the fee for ordering less than MinimumQuantity of a product
)
);
}

public function updateCMSFields(FieldSet &$fields) {
if ($this->owner->ID) {
$SetupFeePrice = $fields->dataFieldByName('SetupFee');
$root = $fields->findOrMakeTab('Root');
$root->removeByName('SetupFee');
$fields->addFieldToTab('Root.Prices', $SetupFeePrice);

}
}

public function updateScaffoldFormFields (&$params) {
$params['fieldClasses']['SetupFee'] = 'SilvercartMoneyField';
$params['restrictFields'][] = 'SetupFee';
}
}

You'd have to extend to to add the other attributes as well. The new attribute shows up in the "Prices"-Tab.

Hope this helps.

Cheers
Ramon

Re: Updating CMS

23 January 2013 at 8:22pm

Thanks Ramon

Regards
Graeme