/** * Generate a daily summary for the overview page * @return array */ protected function getDailySummary() { $strBuffer = ' <div class="tl_formbody_edit be_iso_overview"> <fieldset class="tl_tbox"> <legend style="cursor: default;">' . $GLOBALS['TL_LANG']['ISO_REPORT']['24h_summary'] . '</legend>'; $arrAllowedProducts = \Isotope\Backend\Product\Permission::getAllowedIds(); $objOrders = \Database::getInstance()->prepare("\n SELECT\n c.id AS config_id,\n c.name AS config_name,\n c.currency,\n COUNT(DISTINCT o.id) AS total_orders,\n SUM(i.tax_free_price * i.quantity) AS total_sales,\n SUM(i.quantity) AS total_items\n FROM tl_iso_product_collection o\n LEFT JOIN tl_iso_product_collection_item i ON o.id=i.pid\n LEFT OUTER JOIN tl_iso_config c ON o.config_id=c.id\n WHERE o.type='order' AND o.order_status>0 AND o.locked>=?\n " . Report::getProductProcedure('i', 'product_id') . "\n " . Report::getConfigProcedure('o', 'config_id') . "\n GROUP BY config_id\n ")->execute(strtotime('-24 hours')); if (!$objOrders->numRows) { $strBuffer .= ' <p class="tl_info" style="margin-top:10px">' . $GLOBALS['TL_LANG']['ISO_REPORT']['24h_empty'] . '</p>'; } else { $i = -1; $strBuffer .= ' <br> <table class="tl_listing"> <tr> <th class="tl_folder_tlist">' . $GLOBALS['TL_LANG']['ISO_REPORT']['shop_config'] . '</th> <th class="tl_folder_tlist">' . $GLOBALS['TL_LANG']['ISO_REPORT']['currency'] . '</th> <th class="tl_folder_tlist">' . $GLOBALS['TL_LANG']['ISO_REPORT']['orders#'] . '</th> <th class="tl_folder_tlist">' . $GLOBALS['TL_LANG']['ISO_REPORT']['products#'] . '</th> <th class="tl_folder_tlist">' . $GLOBALS['TL_LANG']['ISO_REPORT']['sales#'] . '</th> </tr>'; while ($objOrders->next()) { $strBuffer .= ' <tr class="row_' . ++$i . ($i % 2 ? 'odd' : 'even') . '"> <td class="tl_file_list">' . $objOrders->config_name . '</td> <td class="tl_file_list">' . $objOrders->currency . '</td> <td class="tl_file_list">' . $objOrders->total_orders . '</td> <td class="tl_file_list">' . $objOrders->total_items . '</td> <td class="tl_file_list">' . Isotope::formatPrice($objOrders->total_sales) . '</td> </tr>'; } $strBuffer .= ' </table>'; } $strBuffer .= ' </fieldset> </div>'; return $strBuffer; }
/** * Return string to filter database query by user allowed products * * @param string $strTable Table name or alias (optional) * @param string $strField Table field or alias (optional) * @param string $strPrefix Prefix for query (e.g. AND) * * @return string */ public static function getProductProcedure($strTable = 'tl_iso_product', $strField = 'id', $strPrefix = ' AND ') { $arrAllowedProducts = Permission::getAllowedIds(); if (true === $arrAllowedProducts) { return ''; } if (false === $arrAllowedProducts || empty($arrAllowedProducts)) { $arrAllowedProducts = array(0); } return $strPrefix . $strTable . '.' . $strField . ' IN (' . implode(',', $arrAllowedProducts) . ')'; }
/** * Returns an array of all allowed product IDs and variant IDs for the current backend user * * @return array|bool * @deprecated will be removed in Isotope 3.0 */ public static function getAllowedProductIds() { return \Isotope\Backend\Product\Permission::getAllowedIds(); }
/** * Publish/unpublish a product * * @param int $intId * @param bool $blnVisible */ protected function toggleVisibility($intId, $blnVisible) { // Check permissions to edit \Input::setGet('id', $intId); \Input::setGet('act', 'toggle'); Permission::check(); /** @var \BackendUser $user */ $user = \BackendUser::getInstance(); // Check permissions to publish if (!$user->isAdmin && !$user->hasAccess('tl_iso_product::published', 'alexf')) { \System::log('Not enough permissions to publish/unpublish product ID "' . $intId . '"', __METHOD__, TL_ERROR); \Controller::redirect('contao/main.php?act=error'); } $objVersions = new \Versions('tl_iso_product', $intId); $objVersions->initialize(); // Trigger the save_callback if (is_array($GLOBALS['TL_DCA']['tl_iso_product']['fields']['published']['save_callback'])) { foreach ($GLOBALS['TL_DCA']['tl_iso_product']['fields']['published']['save_callback'] as $callback) { $objCallback = \System::importStatic($callback[0]); $blnVisible = $objCallback->{$callback}[1]($blnVisible, $this); } } // Update the database \Database::getInstance()->prepare("UPDATE tl_iso_product SET published='" . ($blnVisible ? 1 : '') . "' WHERE id=?")->execute($intId); $objVersions->create(); $this->log('A new version of record "tl_iso_product.id=' . $intId . '" has been created' . $this->getParentEntries('tl_iso_product', $intId), __METHOD__, TL_GENERAL); }