本文整理汇总了PHP中Pack::allUsesAdvancedStockManagement方法的典型用法代码示例。如果您正苦于以下问题:PHP Pack::allUsesAdvancedStockManagement方法的具体用法?PHP Pack::allUsesAdvancedStockManagement怎么用?PHP Pack::allUsesAdvancedStockManagement使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Pack
的用法示例。
在下文中一共展示了Pack::allUsesAdvancedStockManagement方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: ajaxProcessProductQuantity
public function ajaxProcessProductQuantity()
{
if ($this->tabAccess['edit'] === '0') {
return die(Tools::jsonEncode(array('error' => $this->l('You do not have the right permission'))));
}
if (!Tools::getValue('actionQty')) {
return Tools::jsonEncode(array('error' => $this->l('Undefined action')));
}
$product = new Product((int) Tools::getValue('id_product'), true);
switch (Tools::getValue('actionQty')) {
case 'depends_on_stock':
if (Tools::getValue('value') === false) {
die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
}
if ((int) Tools::getValue('value') != 0 && (int) Tools::getValue('value') != 1) {
die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
}
if (!$product->advanced_stock_management && (int) Tools::getValue('value') == 1) {
die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. '))));
}
if (Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) Tools::getValue('value') == 1 && (Pack::isPack($product->id) && !Pack::allUsesAdvancedStockManagement($product->id) && ($product->pack_stock_type == 2 || $product->pack_stock_type == 1 || $product->pack_stock_type == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2)))) {
die(Tools::jsonEncode(array('error' => $this->l('You cannot use advanced stock management for this pack because') . '<br />' . $this->l('- advanced stock management is not enabled for these products') . '<br />' . $this->l('- you have chosen to decrement products quantities.'))));
}
StockAvailable::setProductDependsOnStock($product->id, (int) Tools::getValue('value'));
break;
case 'pack_stock_type':
$value = Tools::getValue('value');
if ($value === false) {
die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
}
if ((int) $value != 0 && (int) $value != 1 && (int) $value != 2 && (int) $value != 3) {
die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
}
if ($product->depends_on_stock && !Pack::allUsesAdvancedStockManagement($product->id) && ((int) $value == 1 || (int) $value == 2 || (int) $value == 3 && (Configuration::get('PS_PACK_STOCK_TYPE') == 1 || Configuration::get('PS_PACK_STOCK_TYPE') == 2))) {
die(Tools::jsonEncode(array('error' => $this->l('You cannot use this stock management option because:') . '<br />' . $this->l('- advanced stock management is not enabled for these products') . '<br />' . $this->l('- advanced stock management is enabled for the pack'))));
}
Product::setPackStockType($product->id, $value);
break;
case 'out_of_stock':
if (Tools::getValue('value') === false) {
die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
}
if (!in_array((int) Tools::getValue('value'), array(0, 1, 2))) {
die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
}
StockAvailable::setProductOutOfStock($product->id, (int) Tools::getValue('value'));
break;
case 'set_qty':
if (Tools::getValue('value') === false || !is_numeric(trim(Tools::getValue('value')))) {
die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
}
if (Tools::getValue('id_product_attribute') === false) {
die(Tools::jsonEncode(array('error' => $this->l('Undefined id product attribute'))));
}
StockAvailable::setQuantity($product->id, (int) Tools::getValue('id_product_attribute'), (int) Tools::getValue('value'));
Hook::exec('actionProductUpdate', array('id_product' => (int) $product->id, 'product' => $product));
// Catch potential echo from modules
$error = ob_get_contents();
if (!empty($error)) {
ob_end_clean();
die(Tools::jsonEncode(array('error' => $error)));
}
break;
case 'advanced_stock_management':
if (Tools::getValue('value') === false) {
die(Tools::jsonEncode(array('error' => $this->l('Undefined value'))));
}
if ((int) Tools::getValue('value') != 1 && (int) Tools::getValue('value') != 0) {
die(Tools::jsonEncode(array('error' => $this->l('Incorrect value'))));
}
if (!Configuration::get('PS_ADVANCED_STOCK_MANAGEMENT') && (int) Tools::getValue('value') == 1) {
die(Tools::jsonEncode(array('error' => $this->l('Not possible if advanced stock management is disabled. '))));
}
$product->setAdvancedStockManagement((int) Tools::getValue('value'));
if (StockAvailable::dependsOnStock($product->id) == 1 && (int) Tools::getValue('value') == 0) {
StockAvailable::setProductDependsOnStock($product->id, 0);
}
break;
}
die(Tools::jsonEncode(array('error' => false)));
}