Source of file BundleEntry.php
Size: 2,080 Bytes - Last Modified: 2021-12-24T06:40:39+00:00
/var/www/docs.ssmods.com/process/src/src/model/BundleEntry.php
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 | <?php namespace Cita\eCommerce\Model; use SilverStripe\Dev\Debug; use SilverStripe\ORM\DataObject; /** * Description * * @package silverstripe * @subpackage mysite */ class BundleEntry extends DataObject { private static $table_name = 'Cita_eCommerce_BundleEntry'; private static $db = [ 'Title' => 'Varchar(128)', 'Price' => 'Currency', 'Quantity' => 'Int', ]; private static $defaults = [ 'Quantity' => 1 ]; private static $has_one = [ 'Bundle' => Bundle::class, 'Order' => Order::class ]; private static $many_many = [ 'Variants' => Variant::class ]; private static $many_many_extraFields = [ 'Variants' => [ 'Quantity' => 'Int', 'Delivered' => 'Boolean', ] ]; public function getUnitWeight() { return $this->Variants()->sum('UnitWeight'); } public function getData() { return [ 'id' => $this->ID, 'is_bundle' => true, 'title' => $this->Title, 'price' => $this->Price, 'pagelink' => $this->Bundle()->Link(), 'price_label' => '$' . number_format($this->Price, 2), 'image' => $this->Bundle()->Image()->getData('ScaleHeight', 100), 'quantity' => 1, // maybe should allow stack 'variants' => array_map(function($v) { return array_merge( $v->Data, [ 'count' => $v->Quantity, 'quantity' => $v->Quantity, 'delivered' => (boolean) $v->Delivered, ] ); }, $this->Variants()->toArray()) ]; } public function onBeforeWrite() { parent::onBeforeWrite(); if ($this->Bundle()->exists()) { $this->Tilte = $this->Bundle()->Title; } } public function onBeforeDelete() { parent::onBeforeDelete(); $this->Variants()->removeAll(); } } |