/**
  * Checks whether there is a status change needed and executes the change if 
  * needed.
  * 
  * @param int  $stockQuantityBefore Stock quantity before change.
  * @param bool $doWrite             Set to false to prevent a write.
  * 
  * @return void
  *
  * @author Sebastian Diel <*****@*****.**>
  * @since 11.06.2014
  */
 protected function checkForAvailabilityStatusChange($stockQuantityBefore, $doWrite = true)
 {
     if ($this->StockQuantity <= 0 && $stockQuantityBefore > 0) {
         // check for automatic negative availability status and set it.
         $newStatus = SilvercartAvailabilityStatus::get_negative_status();
         if ($newStatus instanceof SilvercartAvailabilityStatus) {
             $this->SilvercartAvailabilityStatusID = $newStatus->ID;
             if ($doWrite) {
                 $this->write();
             }
         }
     } elseif ($this->StockQuantity > 0 && $stockQuantityBefore <= 0) {
         // check for automatic positive availability status and set it.
         $newStatus = SilvercartAvailabilityStatus::get_positive_status();
         if ($newStatus instanceof SilvercartAvailabilityStatus) {
             $this->SilvercartAvailabilityStatusID = $newStatus->ID;
             if ($doWrite) {
                 $this->write();
             }
         }
     }
 }