Source of file AccessoriesPage.php
Size: 3,329 Bytes - Last Modified: 2021-12-23T10:52:26+00:00
/var/www/docs.ssmods.com/process/src/code/CheckoutSteps/code/pages/AccessoriesPage.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125 | <?php class AccessoriesPage extends ProductCategory { private static $singular_name = "Accessories Holder Page"; private static $plural_name = "Accessories Holder Pages"; private static $icon = 'toast-shop-modules/CheckoutSteps/images/icons/shopping-basket--arrow.png'; private static $db = array( 'MoreProductsText' => 'Varchar(100)' ); private static $has_one = array( 'MoreProductsImage' => 'Image' ); public function getCMSFields() { $fields = parent::getCMSFields(); $fields->removeByName(array( 'Content', 'HeroText', 'HeroImage' )); $fields->addFieldsToTab('Root.Main', array( TextField::create('MoreProductsText'), UploadField::create('MoreProductsImage') )); return $fields; } } /** * Class AccessoriesPage_Controller * * @property AccessoriesPage dataRecord * @method AccessoriesPage data() * @mixin AccessoriesPage dataRecord */ class AccessoriesPage_Controller extends ProductCategory_Controller { private static $allowed_actions = array( 'proceed' ); public function proceed() { $cart = ShoppingCart::singleton(); foreach ($_POST as $name => $val) { if (StringUtils::StartsWith($name, 'product__') && (int)$val) { $id = str_replace('product__', '', $name); $product = Product::get()->byID((int)$id); if ($product) { $variations = $product->Variations(); if ($variations->count()) { $cart->add($variations->first(), (int)$val); } else { $cart->add($product, (int)$val); } } } } $order = $cart->current(); if ($order) { $order->calculate(); $order->write(); } $nextPage = null; $nextPage = ReviewOrderPage::get()->first(); if ($nextPage) { return $this->redirect($nextPage->Link()); } return $this->httpError(404); } /** * Get accessories that are related to what we have in the cart. * * @return DataList|null */ public function getAccessories() { /** ========================================= * @var Order $order * ========================================*/ $cart = ShoppingCart::singleton(); $order = $cart->current(); if ($order->Items()) { $productIDs = $order->Items()->column('ProductID'); if (singleton('Product')->hasDatabaseField('BelongsTo')) { /** * TODO: Using PartialMatch for now. * This is fine to match the current sets of product IDs. However, something like "5" would be * matched with the list "55,25,88" and so on. In the future, use the ORM. Have fun sorting out the * edge cases, lol. */ $accessories = Product::get()->filter(array( 'BelongsTo:PartialMatch' => $productIDs )); return $accessories; } } return null; } } |