当前位置: 首页>>代码示例>>PHP>>正文


PHP Audit::getAuditor方法代码示例

本文整理汇总了PHP中Audit::getAuditor方法的典型用法代码示例。如果您正苦于以下问题:PHP Audit::getAuditor方法的具体用法?PHP Audit::getAuditor怎么用?PHP Audit::getAuditor使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Audit的用法示例。


在下文中一共展示了Audit::getAuditor方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: doItem

 /**
  * Update/add SKU/quantity to cart, update the price in the cart, save old price and inventory level (if requested)
  *
  * @param int       SKU ID
  * @param string    Update Method:  add - adds to the existing quantity,
  *                                  set - ignores existing quantity and sets a new value,
  *                                  sync - simply checks/updates inventory and pricing
  * @param int       Quantity
  * @param bool      Flag determining whether the old qty should be saved (only when it goes down);
  *                  price get saved in either case
  * @return void
  */
 protected function doItem($sId, $mode = 'add', $qty = 1, $retainOldValue = false)
 {
     // Check quantity: must be a positive integer or zero
     if (!Cart_Helper::isNonNegativeInt($qty)) {
         throw new Exception(Lang::txt('COM_CART_INCORRECT_QTY'));
     } elseif ($qty == 0 && !$retainOldValue) {
         // Delete if quantity is set to zero
         if ($mode == 'set') {
             $this->deleteItem($sId);
             return;
         } else {
             throw new Exception(Lang::txt('COM_CART_INCORRECT_QTY'));
         }
     }
     // Check if there is enough inventory (if tracking inventory) taking into account current quantity in the cart
     // Get the quantity already in the cart (if appending or simply syncing)
     if ($mode == 'add' || $mode == 'sync') {
         $skuCartInfo = $this->getCartItem($sId);
     } else {
         $skuCartInfo = new stdClass();
         $skuCartInfo->crtiQty = 0;
     }
     // Get SKU pricing and inventory level & policies
     include_once JPATH_BASE . DS . 'components' . DS . 'com_storefront' . DS . 'models' . DS . 'Warehouse.php';
     $warehouse = new StorefrontModelWarehouse();
     $allSkuInfo = $warehouse->getSkusInfo(array($sId));
     if (empty($allSkuInfo)) {
         throw new Exception(Lang::txt('COM_STOREFRONT_SKU_NOT_FOUND'));
     }
     $skuInfo = $allSkuInfo[$sId]['info'];
     $skuName = $skuInfo->pName;
     if (!empty($allSkuInfo[$sId]['options']) && count($allSkuInfo[$sId]['options'])) {
         foreach ($allSkuInfo[$sId]['options'] as $oName) {
             $skuName .= ', ' . $oName;
         }
     }
     // Check inventory rules (sync mode doesn't check inventory level, just pricing)
     if ($mode != 'sync') {
         // Don't allow purchasing multiple products (same & different SKUs) for those that are not allowed
         if (!$skuInfo->pAllowMultiple) {
             // Check this SKU qty to make sure no multiple SKUs are there
             if (!empty($skuCartInfo->crtiQty) && $skuCartInfo->crtiQty > 0 || $qty > 1) {
                 throw new Exception($skuInfo->pName . Lang::txt('COM_CART_NO_MULTIPLE_ITEMS'));
             }
             // Check if there is this project already in the cart (different SKU)
             $allSkus = $warehouse->getProductSkus($skuInfo->pId);
             foreach ($allSkus as $skuId) {
                 // Skip the current SKU, look only at other SKUs
                 if ($skuId != $sId) {
                     $otherSkuInfo = $this->getCartItem($skuId);
                     // Error if there is already another SKU of the same product in the cart
                     if (!empty($otherSkuInfo->crtiQty) && $otherSkuInfo->crtiQty > 0) {
                         throw new Exception($skuInfo->pName . Lang::txt('COM_CART_NO_MULTIPLE_ITEMS'));
                     }
                 }
             }
         }
         // Don't allow purchasing multiple SKUs for those that are not allowed
         if (!$skuInfo->sAllowMultiple && (!empty($skuCartInfo->crtiQty) && $skuCartInfo->crtiQty > 0 || $qty > 1)) {
             throw new Exception($skuName . Lang::txt('COM_CART_NO_MULTIPLE_ITEMS'));
         }
         // Make sure there is enough inventory
         if ($skuInfo->sTrackInventory) {
             // See if qty can be added
             if ($qty > $skuInfo->sInventory) {
                 throw new Exception(Lang::txt('COM_CART_NOT_ENOUGH_INVENTORY'));
             } elseif (!empty($skuCartInfo->crtiQty) && $qty + $skuCartInfo->crtiQty > $skuInfo->sInventory) {
                 // This is how much they can add: $skuInfo->sInventory - $skuCartInfo->crtiQty
                 throw new Exception(Lang::txt('COM_CART_ADD_TOO_MANY_CART'));
             }
         }
     }
     // Run the auditor
     if ($mode != 'sync') {
         require_once JPATH_BASE . DS . 'components' . DS . 'com_cart' . DS . 'helpers' . DS . 'Audit.php';
         $auditor = Audit::getAuditor($skuInfo, $this->crtId);
         $auditorResponse = $auditor->audit();
         if ($auditorResponse->status == 'error') {
             throw new Exception($skuInfo->pName . $auditor->getResponseError());
         }
     }
     // Insert new values, if exists save the previous price (for possible price changes messaging)
     // and old inventory level (if needed)
     $sql = "INSERT INTO `#__cart_cart_items`\n\t\t\t\t(`crtId`, `sId`, `crtiQty`, `crtiOldQty`, `crtiPrice`, `crtiOldPrice`, `crtiName`)\n\t\t\t\tVALUES\n\t\t\t\t({$this->crtId}, '{$sId}', {$qty}, NULL, {$skuInfo->sPrice}, NULL, " . $this->_db->quote($skuName) . ")\n\t\t\t\tON DUPLICATE KEY UPDATE `crtiOldPrice` = `crtiPrice`, `crtiPrice` = {$skuInfo->sPrice}, `crtiName` = " . $this->_db->quote($skuName);
     // Check if old value has to be retained
     if ($retainOldValue) {
         $sql .= ", `crtiOldQty` = `crtiQty`";
     } else {
//.........这里部分代码省略.........
开发者ID:sumudinie,项目名称:hubzero-cms,代码行数:101,代码来源:Cart.php

示例2: displayTask

 /**
  * Display product
  *
  * @param		$pId
  * @return     	void
  */
 public function displayTask()
 {
     $pId = $this->warehouse->productExists(Request::getVar('product', ''));
     if (!$pId) {
         App::abort(404, Lang::txt('COM_STOREFRONT_PRODUCT_NOT_FOUND'));
     }
     $this->view->pId = $pId;
     $this->view->css();
     $this->view->js('product_display.js');
     // A flag whether the item is available for purchase (for any reason, used by the auditors)
     $productAvailable = true;
     $pageMessages = array();
     // Get the cart
     require_once PATH_CORE . DS . 'components' . DS . 'com_cart' . DS . 'models' . DS . 'CurrentCart.php';
     $cart = new CartModelCurrentCart();
     // POST add to cart request
     $addToCartRequest = Request::getVar('addToCart', false, 'post');
     $options = Request::getVar('og', false, 'post');
     $qty = Request::getInt('qty', 1, 'post');
     if ($addToCartRequest) {
         // Initialize errors array
         $errors = array();
         // Check if passed options/productID map to a SKU
         try {
             $sku = $this->warehouse->mapSku($pId, $options);
             $cart->add($sku, $qty);
         } catch (Exception $e) {
             $errors[] = $e->getMessage();
             $pageMessages[] = array($e->getMessage(), 'error');
         }
         if (!empty($errors)) {
             $this->view->setError($errors);
         } else {
             // prevent resubmitting by refresh
             // If not an ajax call, redirect to cart
             $redirect_url = Route::url('index.php?option=' . 'com_cart');
             App::redirect($redirect_url);
         }
     }
     // Get the product info
     $product = $this->warehouse->getProductInfo($pId);
     $this->view->product = $product;
     // Run the auditor
     require_once PATH_CORE . DS . 'components' . DS . 'com_cart' . DS . 'helpers' . DS . 'Audit.php';
     $auditor = Audit::getAuditor($product, $cart->getCartInfo()->crtId);
     $auditorResponse = $auditor->audit();
     //print_r($auditor); die;
     if (!empty($auditorResponse) && $auditorResponse->status != 'ok') {
         if ($auditorResponse->status == 'error') {
             // Product is not available for purchase
             $productAvailable = false;
             foreach ($auditorResponse->notices as $notice) {
                 $pageMessages[] = array($notice, 'warning');
             }
         }
     }
     // Get option groups with options and SKUs
     $data = $this->warehouse->getProductOptions($pId);
     if ($data) {
         //throw new Exception(Lang::txt('COM_STOREFRONT_PRODUCT_ERROR'), 404);
         $this->view->options = $data->options;
     }
     //print_r($data); die;
     // Find a price range for the product
     $priceRange = array('high' => 0, 'low' => false);
     /*
     	Find if there is a need to display a product quantity dropdown on the initial view load. It will be only displayed for single SKU that allows multiple items.
     	For multiple SKUs it will be generated by JS (no drop-down for non-JS users, sorry)
     */
     $qtyDropDownMaxVal = 0;
     $inStock = true;
     if (!$data || !count($data->skus)) {
         $inStock = false;
     }
     $this->view->inStock = $inStock;
     if ($data && count($data->skus) == 1) {
         // Set the max value for the dropdown QTY
         // TODO: add it to the SKU table to set on the per SKU level
         $qtyDropDownMaxValLimit = 20;
         // Get the first and the only value
         $sku = array_shift(array_values($data->skus));
         // If no inventory tracking, there is no limit on how many can be purchased
         $qtyDropDownMaxVal = $qtyDropDownMaxValLimit;
         if ($sku['info']->sTrackInventory) {
             $qtyDropDownMaxVal = $sku['info']->sInventory;
         }
         if ($qtyDropDownMaxVal < 1) {
             $qtyDropDownMaxVal = 1;
         } elseif ($qtyDropDownMaxVal > $qtyDropDownMaxValLimit) {
             $qtyDropDownMaxVal = $qtyDropDownMaxValLimit;
         }
         // If the SKU doesn't allow multiple items, set the dropdown to 1
         if (!$sku['info']->sAllowMultiple) {
             $qtyDropDownMaxVal = 1;
//.........这里部分代码省略.........
开发者ID:sumudinie,项目名称:hubzero-cms,代码行数:101,代码来源:product.php


注:本文中的Audit::getAuditor方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。