示例#1
0
 public function checkAttributeStockRoom($data = array(), $productData = array())
 {
     $stockroomhelper = new rsstockroomhelper();
     $newquantity = $data['quantity'];
     $attArr = $data['cart_attribute'];
     $product_preorder = $productData->preorder;
     for ($i = 0; $i < count($attArr); $i++) {
         $propArr = $attArr[$i]['attribute_childs'];
         for ($k = 0; $k < count($propArr); $k++) {
             if (USE_STOCKROOM == 1) {
                 if ($product_preorder == "global" && !ALLOW_PRE_ORDER || $product_preorder == "no" || $product_preorder == "" && !ALLOW_PRE_ORDER) {
                     $property_stock = $stockroomhelper->getStockroomTotalAmount($propArr[$k]['property_id'], "property");
                 }
                 if ($product_preorder == "global" && ALLOW_PRE_ORDER || $product_preorder == "yes" || $product_preorder == "" && ALLOW_PRE_ORDER) {
                     $regular_property_stock = $stockroomhelper->getStockroomTotalAmount($propArr[$k]['property_id'], "property");
                     $Preorder_property_stock = $stockroomhelper->getPreorderStockroomTotalAmount($propArr[$k]['property_id'], "property");
                     $property_stock = $regular_property_stock + $Preorder_property_stock;
                 }
                 $ownreserveStock = $stockroomhelper->getCurrentUserReservedStock($propArr[$k]['property_id'], "property");
                 if ($property_stock >= 0) {
                     if ($newquantity > $ownreserveStock && $property_stock < $newquantity - $ownreserveStock) {
                         $newquantity = $property_stock + $ownreserveStock;
                     }
                 } else {
                     $newquantity = $property_stock + $ownreserveStock;
                 }
             }
             $subpropArr = $propArr[$k]['property_childs'];
             for ($l = 0; $l < count($subpropArr); $l++) {
                 if (USE_STOCKROOM == 1) {
                     if ($product_preorder == "global" && !ALLOW_PRE_ORDER || $product_preorder == "no" || $product_preorder == "" && !ALLOW_PRE_ORDER) {
                         $subproperty_stock = $stockroomhelper->getStockroomTotalAmount($subpropArr[$l]['subproperty_id'], "subproperty");
                     }
                     if ($product_preorder == "global" && ALLOW_PRE_ORDER || $product_preorder == "yes" || $product_preorder == "" && ALLOW_PRE_ORDER) {
                         $regular_subproperty_stock = $stockroomhelper->getStockroomTotalAmount($subpropArr[$l]['subproperty_id'], "subproperty");
                         $preorder_subproperty_stock = $stockroomhelper->getPreorderStockroomTotalAmount($subpropArr[$l]['subproperty_id'], "subproperty");
                         $subproperty_stock = $regular_subproperty_stock + $preorder_subproperty_stock;
                     }
                     $ownreserveStock = $stockroomhelper->getCurrentUserReservedStock($propArr[$k]['property_id'], "property");
                     if ($subproperty_stock >= 0) {
                         if ($newquantity > $ownreserveStock && $subproperty_stock < $newquantity - $ownreserveStock) {
                             $newquantity = $subproperty_stock + $ownreserveStock;
                         }
                     } else {
                         $newquantity = $subproperty_stock + $ownreserveStock;
                     }
                 }
             }
         }
     }
     if ($productData->max_order_product_quantity > 0 && $productData->max_order_product_quantity < $newquantity) {
         $newquantity = $productData->max_order_product_quantity;
     }
     for ($i = 0; $i < count($attArr); $i++) {
         $propArr = $attArr[$i]['attribute_childs'];
         for ($k = 0; $k < count($propArr); $k++) {
             $stockroomhelper->addReservedStock($propArr[$k]['property_id'], $newquantity, "property");
             $subpropArr = $propArr[$k]['property_childs'];
             for ($l = 0; $l < count($subpropArr); $l++) {
                 $stockroomhelper->addReservedStock($subpropArr[$l]['subproperty_id'], $newquantity, "subproperty");
             }
         }
     }
     return $newquantity;
 }