本文整理汇总了PHP中Warehouse::getProductSkus方法的典型用法代码示例。如果您正苦于以下问题:PHP Warehouse::getProductSkus方法的具体用法?PHP Warehouse::getProductSkus怎么用?PHP Warehouse::getProductSkus使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Warehouse
的用法示例。
在下文中一共展示了Warehouse::getProductSkus方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: addTask
public function addTask()
{
$response = new \stdClass();
$response->status = 'ok';
include_once JPATH_COMPONENT . DS . 'models' . DS . 'cart.php';
$cart = new CurrentCart();
// update cart
$updateCartRequest = Request::getVar('updateCart', false, 'post');
$pIds = Request::getVar('pId', false, 'post');
//print_r($pIds); die;
// If pIds are posted, convert them to SKUs
if (!empty($pIds)) {
$skus = array();
$warehouse = new Warehouse();
foreach ($pIds as $pId => $qty) {
$product_skus = $warehouse->getProductSkus($pId);
// must be only one sku to work
if (sizeof($product_skus) != 1) {
// each pId must map to one SKU, otherwise ignored
continue;
}
$skus[$product_skus[0]] = $qty;
}
} else {
$skus = Request::getVar('skus', false, 'post');
}
//print_r($skus); die;
// Initialize errors array
$errors = array();
if ($updateCartRequest && $skus) {
// Turn off syncing to prevent redundant session update queries
$cart->setSync(false);
foreach ($skus as $sId => $qty) {
try {
$cart->update($sId, $qty);
} catch (\Exception $e) {
$errors[] = $e->getMessage();
}
}
}
// add coupon if needed
$addCouponRequest = Request::getVar('addCouponCode', false, 'post');
$couponCode = Request::getVar('couponCode', false, 'post');
if ($addCouponRequest && $couponCode) {
// Sync cart before pontial coupons applying
$cart->getCartInfo(true);
// Initialize errors array
$errors = array();
// Add coupon
try {
$cart->addCoupon($couponCode);
} catch (\Exception $e) {
$errors[] = $e->getMessage();
}
}
if (!empty($errors)) {
$response->status = 'error';
$response->errors = $errors;
}
echo htmlspecialchars(json_encode($response), ENT_NOQUOTES);
die;
}
示例2: homeTask
/**
* Display default page
*
* @return void
*/
public function homeTask()
{
$cart = new CurrentCart();
//print_r($this); die;
// Initialize errors array
$errors = array();
// Update cart if needed
$updateCartRequest = Request::getVar('updateCart', false, 'post');
// If pIds are posted, convert them to SKUs
$pIds = Request::getVar('pId', false, 'post');
//print_r($pIds); die;
$skus = Request::getVar('skus', false, 'post');
if ($updateCartRequest && ($pIds || $skus)) {
if (!empty($pIds)) {
$skus = array();
$warehouse = new Warehouse();
foreach ($pIds as $pId => $qty) {
$product_skus = $warehouse->getProductSkus($pId);
// each pId must map to one SKU, otherwise ignored, since there is no way which SKU is being added
// Must be only one sku...
if (sizeof($product_skus) != 1) {
continue;
}
$skus[$product_skus[0]] = $qty;
}
} else {
if (!is_array($skus)) {
$skus = array($skus => 1);
}
}
//print_r($skus); die;
// Turn off syncing to prevent redundant session update queries
$cart->setSync(false);
foreach ($skus as $sId => $qty) {
try {
$cart->update($sId, $qty);
} catch (\Exception $e) {
$cart->setMessage($e->getMessage(), 'error');
}
}
// set flag to redirect
$redirect = true;
if ($cart->hasMessages()) {
$redirect = false;
}
} else {
$allPost = Request::request();
foreach ($allPost as $var => $val) {
if ($val == 'delete') {
$toDelete = explode('_', $var);
if ($toDelete[0] == 'delete') {
$sId = $toDelete[1];
// Delete the requested item by setting its QTY to zero
$redirect = true;
try {
$cart->update($sId, 0);
} catch (\Exception $e) {
$cart->setMessage($e->getMessage(), 'error');
$redirect = false;
}
}
}
}
}
// Add coupon if needed
$addCouponRequest = Request::getVar('addCouponCode', false, 'post');
$couponCode = Request::getVar('couponCode', false, 'post');
if ($addCouponRequest && $couponCode) {
// Sync cart before pontial coupons applying
$cart->getCartInfo(true);
// Add coupon
try {
$cart->addCoupon($couponCode);
} catch (\Exception $e) {
$cart->setMessage($e->getMessage(), 'error');
}
// set flag to redirect
$redirect = true;
if ($cart->hasMessages()) {
$redirect = false;
}
}
// Check for express add to cart
if (!empty($redirect) && $redirect) {
// If this is an express checkout (go to the confirm page right away) there shouldn't be any items in the cart
// Since redirect is set, there are no errors
$expressCheckout = Request::getVar('expressCheckout', false, 'post');
// make sure the cart is empty
if ($expressCheckout && !empty($skus) && $cart->isEmpty()) {
// Get the latest synced cart info, it will also enable cart syncing that was turned off before
$cart->getCartInfo(true);
// Redirect directly to checkout, skip the cart page
App::redirect(Route::url('index.php?option=' . $this->_option) . DS . 'checkout');
}
// prevent resubmitting form by refresh
//.........这里部分代码省略.........
示例3: update
/**
* Update product info
*
* @param void
* @return object info
*/
public function update()
{
// For single product update SKU must save the original SKU ID (since SKU was generated automatically)
// Find the SKU ID for this product and save
$warehouse = new Warehouse();
$sku = $warehouse->getProductSkus($this->data->id);
// Must be just one SKU
if (sizeof($sku) != 1) {
throw new \Exception(Lang::txt('Only one SKU is allowed'));
}
$skuId = $sku[0];
// save product sku with the current ID to resave the changes with this ID
$sku = $this->getSku()->setId($skuId);
return parent::update();
}