/** * Add load information to the Products/Services homepage panel * * @param Item $basePanel collection of homepage panels */ function populateLoadAverageInHomepagePanels(Item $basePanel) { $servicesPanel = $basePanel->getChild('Active Products/Services'); // If this is not populated at all we need to skip adding items. if (is_null($servicesPanel)) { return; } foreach ($servicesPanel->getChildren() as $serviceLink) { parse_str(parse_url($serviceLink->getUri(), PHP_URL_QUERY)); /** @var int $id Created by parse_str() */ /** @var Service $service */ // See http://docs.whmcs.com/classes/classes/WHMCS.Service.Service.html for details on this model $service = Service::findOrFail($id); $loadAverage = getLoadAverageFromService($service); if ($loadAverage) { $label = $serviceLink->getLabel(); $label .= "<br>Load average - One: {$loadAverage->one} "; $label .= "Five: {$loadAverage->five} "; $label .= "Fifteen: {$loadAverage->fifteen}"; $serviceLink->setLabel($label); } } }
*/ $recommendedProducts = ['hostingaccount' => ['Try out our cool cPanel thinger!', 'Buy our SSL certs!'], 'reselleraccount' => ['Goodness gracious the paper!', 'Where the cash at?', 'Where the stash at?'], 'server' => ['Buy more bandwidth!', 'Buy more hard drives!', 'Buy more RAM!'], 'other' => ['Other is really a pretty big category', 'How do I recommend anything for this?', 'I mean damn']]; /** * The panel on the checkout page that contains recommended products. * * @var MenuItem */ $recommendedProductsPanel = null; // Build a sidebar panel with related product items on the cart checkout page. add_hook('PreCalculateCartTotals', 1, function (array $parameters) use($recommendedProducts, &$recommendedProductsPanel) { // Don't build a panel if there's nothing in the cart (because there's // nothing to recommend!) if (count($parameters['products']) == 0) { return; } $recommendedProductsPanel = new MenuItem('Related Products', new MenuFactory()); // Look through the products in the cart and instantiate a new Product // object based off the product's id. foreach ($parameters['products'] as $product) { $product = Product::find($product['pid']); // Add the product type's related products to the new panel. foreach ($recommendedProducts[$product->type] as $recommendedProduct) { $recommendedProductsPanel->addChild($recommendedProduct); } } }); // Assign the new panel to the secondary sidebar. add_hook('ClientAreaSecondarySidebar', 1, function (MenuItem $secondarySidebar) use(&$recommendedProductsPanel) { // $recommendedProductsPanel is only defined on the cart checkout page, // so if it's null then the user is on another page and we shouldn't // edit the sidebar.