/** * Removes the given related product combination * * @param string $passkey * @param int $intProductId * @return string */ public function remove_product_qty_pricing($passkey, $intProductId) { if (!$this->check_passkey($passkey)) { return self::FAIL_AUTH; } try { ProductQtyPricing::model()->deleteAll('product_id= ' . $intProductId); } catch (Exception $e) { _xls_log("SOAP ERROR " . $e); return self::UNKNOWN_ERROR; } return self::OK; }
/** * Product lookup and optional delete, shows inventory numbers */ public function actionProducts() { if (isset($_POST['pk']) && isset($_POST['name']) && isset($_POST['value'])) { if ($_POST['name'] == 'code' && $_POST['value'] == "") { $items = CartItem::model()->findAll("product_id=" . $_POST['pk'] . " AND (cart_type=" . CartType::order . " OR cart_type=" . CartType::awaitpayment . ")"); if ($items) { echo "You cannot delete a product that has been used on an order"; } else { _dbx("set foreign_key_checks=0;"); Product::model()->updateAll(array('image_id' => null), 'id =' . $_POST['pk']); Images::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductCategoryAssn::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductRelated::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductRelated::model()->deleteAllByAttributes(array('related_id' => $_POST['pk'])); ProductTags::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductQtyPricing::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); ProductText::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); WishlistItem::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); TaskQueue::model()->deleteAllByAttributes(array('product_id' => $_POST['pk'])); Product::model()->deleteByPk($_POST['pk']); _dbx("set foreign_key_checks=1;"); echo "delete"; } } else { echo Yii::t('admin', 'You cannot change a product code here. Delete the code to remove it manually from the Web Store database'); } } else { $model = new Product(); if (isset($_GET['q'])) { $model->code = $_GET['q']; } $this->render("products", array('model' => $model)); } }
/** * Update the Quantity of an Item in the cart * Then force recalculation of Cart values * @param int $intItemId * @param int $intQuantity * @return string[]|true|void|CartItem */ public function UpdateItemQuantity($objItem, $intQuantity) { if ($intQuantity <= 0) { if ($objItem->wishlist_item > 0) { WishlistItem::model()->updateByPk($objItem->wishlist_item, array('cart_item_id' => null)); } $objItem->delete(); return true; } if ($intQuantity == $objItem->qty) { return; } if (_xls_get_conf('PRICE_REQUIRE_LOGIN', 0) == 1 && Yii::app()->user->isGuest) { return array('errorId' => 'notLoggedIn', 'errorMessage' => Yii::t('cart', 'You must log in before Adding to Cart.')); } if (_xls_get_conf('INVENTORY_OUT_ALLOW_ADD', 0) < Product::InventoryAllowBackorders && $intQuantity > $objItem->qty && $objItem->product->inventoried && $objItem->product->inventory_avail < $intQuantity) { if (_xls_get_conf('INVENTORY_DISPLAY', 0) == 0) { $availQty = null; } else { $availQty = $objItem->product->inventory_avail; } return array('errorId' => 'invalidQuantity', 'errorMessage' => Yii::t('cart', 'Your chosen quantity is not available for ordering. Please come back and order later.'), 'availQty' => $availQty); } // qty discount? $arrtmp = ProductQtyPricing::model()->findAllByAttributes(array('product_id' => $objItem->product_id, 'pricing_level' => 1), array('order' => 'qty ASC')); $tmpprice = 0; foreach ($arrtmp as $tmp) { $tmpprice = $intQuantity >= $tmp->qty ? $tmp->price : $tmpprice; } $objItem->discount = $tmpprice > 0 ? $objItem->sell_base - $tmpprice : 0; $objItem->qty = $intQuantity; $objItem->save(); $this->recalculateAndSave(); return $objItem; }
/** * Add a qty-based product pricing * * @param string $passkey * @param int $intProductId * @param int $intPricingLevel * @param float $fltQty * @param double $fltPrice * @return string * @throws SoapFault * * @soap */ public function add_product_qty_pricing($passkey, $intProductId, $intPricingLevel, $fltQty, $fltPrice) { self::check_passkey($passkey); Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=0;')->execute(); $qtyP = new ProductQtyPricing(); $qtyP->product_id = $intProductId; $qtyP->pricing_level = $intPricingLevel + 1; $qtyP->qty = $fltQty; $qtyP->price = $fltPrice; $qtyP->save(); if (!$qtyP->save()) { $strMsg = "Error saving qty pricing {$intProductId}"; Yii::log("SOAP ERROR : {$strMsg} " . print_r($qtyP->getErrors()), 'error', 'application.' . __CLASS__ . "." . __FUNCTION__); throw new SoapFault($strMsg, WsSoapException::ERROR_UNKNOWN); } Yii::app()->db->createCommand('SET FOREIGN_KEY_CHECKS=1;')->execute(); return self::OK; }