Source of file WishListItem.php
Size: 2,275 Bytes - Last Modified: 2021-12-23T10:03:31+00:00
/var/www/docs.ssmods.com/process/src/code/WishListItem.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112 | <?php /** * Links a buyable record to a wishlist * * @author Mark Guinn <mark@adaircreative.com> * @date 08.07.2013 * @package shop_wishlist */ class WishListItem extends DataObject { private static $db = array( 'BuyableID' => 'Int', 'BuyableClassName' => 'Varchar(60)', ); private static $indexes = array( "BuyableID" => true, "BuyableClassName" => true ); private static $has_one = array( 'WishList' => 'WishList', ); private static $casting = array( 'UnitPrice' => 'Currency', ); /** * @param Buyable|BuyableModel $item * @return $this */ public function setBuyable($item) { $this->BuyableID = $item->ID; $this->BuyableClassName = $item->ClassName; return $this; } /** * @return DataObject|null */ public function getBuyable() { if (!$this->BuyableClassName || !$this->BuyableID) { return null; } return DataObject::get($this->BuyableClassName)->byID($this->BuyableID); } public function Buyable() { return $this->getBuyable(); } /** * @return Float */ public function getUnitPrice() { $product = $this->getBuyable(); if ($product && $product->exists()) { return $product->sellingPrice(); } } public function UnitPrice() { return $this->getUnitPrice(); } /** * @return Currency */ public function getUnitPriceAsMoney() { $out = new Currency('UnitPrice'); $out->setValue($this->getUnitPrice()); return $out; } public function UnitPriceAsMoney() { return $this->getUnitPriceAsMoney(); } /** * @return string */ public function TableTitle() { $buyable = $this->getBuyable(); $item = $buyable->hasMethod('Item') ? $buyable->Item() : null; return $item ? $item->TableTitle() : $buyable->Title; } /** * @return String */ public function SubTitle() { $buyable = $this->getBuyable(); return $buyable->hasMethod('Item') ? $buyable->Item()->SubTitle() : ''; } } |