Source of file EcommerceConfigAjaxDefinitions.php
Size: 7,777 Bytes - Last Modified: 2021-12-23T10:39:35+00:00
/var/www/docs.ssmods.com/process/src/src/Config/EcommerceConfigAjaxDefinitions.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340 | <?php namespace Sunnysideup\Ecommerce\Config; use SilverStripe\Core\ClassInfo; use SilverStripe\Core\Injector\Injector; use SilverStripe\ORM\DataObject; use SilverStripe\View\ViewableData; use Sunnysideup\Ecommerce\Api\ClassHelpers; use Sunnysideup\Ecommerce\Model\Address\OrderAddress; use Sunnysideup\Ecommerce\Model\Order; use Sunnysideup\Ecommerce\Pages\ProductGroup; /** * This class defines all the names for IDs and Classes that are used * within the e-commerce ajax framework. * * @authors: Nicolaas [at] Sunny Side Up .co.nz * @package: ecommerce * @sub-package: configuration */ class EcommerceConfigAjaxDefinitions extends ViewableData { /** * the class that is requesting the ajax definitions * we provide the requestor so that we can dynamically change * the ids and classes, using the requestor. * e.g. * <code> * MyTableRowID(){ * return $this->requestor->ClassName."_bla".$this->requestor->ID; * } * </code>. * * @var DataObject */ protected $requestor; /** * prefix used for all classes and IDs. * * @var string */ private static $prefix; /** * set the requestor. * * @param dataObject $do - the object that requested the data */ public function setRequestor(DataObject $do): self { if (null === self::$prefix) { self::$prefix = EcommerceConfig::get(Order::class, 'template_id_prefix'); } $this->requestor = $do; return $this; } /*___________________ 0. without context ___________________*/ /** * id that is used in templates and in the JSON return @see CartResponse * The Side bar cart ID is used for populating a small cart on the side bar. * * @see Sidebar_Cart.ss * * @return string */ public function SideBarCartID() { return self::$prefix . 'Side_Bar_Cart'; } /** * Small representation of cart. * * @see CartShort.ss * * @return string */ public function SmallCartID() { return self::$prefix . 'small_cart_id'; } /** * class that is used in templates and in the JSON return @see CartResponse * The Menu Cart class is used for populating a tiny cart on your site * (e.g. you have 3 items in your cart ($1343)). * * @see CartTiny.ss * * @return string */ public function TinyCartClassName() { return self::$prefix . 'tiny_cart_class'; } /** * @return string */ public function HiddenPageTitleID() { return self::$prefix . 'HiddenPageTitle'; } /** * @return string */ public function ProductListHolderID() { return self::$prefix . ClassInfo::shortName(ProductGroup::class); } /** * @return string */ public function ProductListAjaxifiedLinkClassName() { return self::$prefix . 'ajaxifyMyProductGroupLinks'; } /** * List of products in the ProductGroup page... * * @see ProductGroupItem.ss, ProductGroupItemMoreDetail.ss, and ProductGroupItemShort.ss * * @return string */ public function ProductListItemClassName() { return self::$prefix . 'productActions'; } /** * Class used to identify that a product is in cart. * * @see ProductGroupItem.ss, ProductGroupItemMoreDetail.ss, and ProductGroupItemShort.ss * * @return string */ public function ProductListItemInCartClassName() { return self::$prefix . 'inCart'; } /** * Class used to identify that a product is not in cart. * * @see ProductGroupItem.ss, ProductGroupItemMoreDetail.ss, and ProductGroupItemShort.ss * * @return string */ public function ProductListItemNotInCartClassName() { return self::$prefix . 'notInCart'; } /*___________________ 1. Generic (Order / Modifier / OrderItem) ___________________*/ /** * @return string for use in the Templates */ public function TableID() { return self::$prefix . ClassHelpers::sanitise_class_name($this->requestor->ClassName) . '_DB_' . $this->requestor->ID; } /** * @return string for use in the Templates */ public function TableTotalID() { return $this->TableID() . '_Total'; } /*___________________ 2. Order ___________________*/ /** * id that is used in templates and in the JSON return @see CartResponse. * * @return string */ public function TableMessageID() { return $this->TableID() . '_Message'; } /** * id that is used in templates and in the JSON return @see CartResponse. * * @return string */ public function TableSubTotalID() { return $this->TableID() . '_SubTotal'; } /** * class that is used in templates and in the JSON return @see CartResponse. * * @return string */ public function TotalItemsTimesQuantityClassName() { return self::$prefix . 'number_of_items_times_quantity'; } /** * class that is used in templates and in the JSON return @see CartResponse. * * @return string */ public function TotalItemsClassName() { return self::$prefix . 'number_of_items'; } /** * class that is used in templates and in the JSON return @see CartResponse. * * @return string */ public function ExpectedCountryClassName() { return self::$prefix . 'expected_country_selector'; } /** * class that is used in templates and in the JSON return @see CartResponse. * * @return string */ public function CountryFieldID() { return OrderAddress::get_country_field_ID(); } /** * class that is used in templates and in the JSON return @see CartResponse. * * @return string */ public function RegionFieldID() { return OrderAddress::get_region_field_ID(); } /*___________________ 3. Order Attribute (Modifier + OrderItem) ___________________*/ /** * @return string for use in the Templates */ public function TableTitleID() { return $this->TableID() . '_Title'; } /** * @return string for use in the Templates */ public function CartTitleID() { return $this->TableID() . '_Title_Cart'; } /** * @return string for use in the Templates */ public function TableSubTitleID() { return $this->TableID() . '_Sub_Title'; } /** * @return string for use in the Templates */ public function CartSubTitleID() { return $this->TableID() . '_Sub_Title_Cart'; } /*___________________ 4. OrderItems ___________________*/ /** * id that is used in templates and in the JSON return @see CartResponse. * * @return string */ public function QuantityFieldName() { return $this->TableID() . '_Quantity_SetQuantityLink'; } /*___________________ 5. Modifiers ___________________*/ /*___________________ 6. Buyable ___________________*/ /** * returns a string that can be used as a unique Identifier for use in templates, etc... * * @return string */ public function UniqueIdentifier() { return $this->TableID() . '_Button'; } public function Define($name) { $object = Injector::inst()->get(EcommerceConfigDefinitions::class); return $object->getAjaxMethod($name); } } |