/**
  * Action to return specific version of a product variation.
  * This can be any product to enable the retrieval of deleted products.
  * This is really useful for sold products where you want to retrieve the actual version that you sold.
  * @param Int $id
  * @param Int $version
  * @return DataObject | Null
  */
 function getVersionOfBuyable($id = 0, $version = 0)
 {
     if (!$id) {
         $id = $this->ID;
     }
     if (!$version) {
         $version = $this->Version;
     }
     return OrderItem::get_version($this->ClassName, $id, $version);
 }
 /**
  * Action to return specific version of a specific product.
  * This can be any product to enable the retrieval of deleted products.
  * This is really useful for sold products where you want to retrieve the actual version that you sold.
  * If the version can not be found then we retrieve the current one.
  * @param Int $id
  * @param Int $version
  * @return DataObject | Null
  */
 function getVersionOfBuyable($id = 0, $version = 0)
 {
     if (!$id) {
         $id = $this->ID;
     }
     if (!$version) {
         $version = $this->Version;
     }
     //not sure why this is running via OrderItem...
     $obj = OrderItem::get_version($this->ClassName, $id, $version);
     if (!$obj) {
         $className = $this->ClassName;
         $obj = $className::get()->byID($id);
     }
     return $obj;
 }
Esempio n. 3
0
 /**
  *
  * @return DataObject (Any type of Data Object that is buyable)
  * @param Boolean $current - is this a current one, or an older VERSION ?
  **/
 function Buyable($current = false)
 {
     if (!$this->BuyableID) {
         return null;
     }
     //start hack
     if (!$this->BuyableClassName) {
         $this->BuyableClassName = str_replace("_OrderItem", "", $this->ClassName);
     }
     $turnTranslatableBackOn = false;
     if (Object::has_extension($this->BuyableClassName, 'Translatable')) {
         Translatable::disable_locale_filter();
         $turnTranslatableBackOn = true;
     }
     //end hack!
     $obj = null;
     if ($current) {
         $obj = DataObject::get_by_id($this->BuyableClassName, $this->BuyableID);
     }
     //run if current not available or current = false
     if (!$obj && $this->Version) {
         /* @TODO: check if the version exists?? - see sample below
         			$versionTable = $this->BuyableClassName."_versions";
         			$dbConnection = DB::getConn();
         			if($dbConnection && $dbConnection instanceOf MySQLDatabase && $dbConnection->hasTable($versionTable)) {
         				$result = DB::query("
         					SELECT COUNT(\"ID\")
         					FROM \"$versionTable\"
         					WHERE
         						\"RecordID\" = ".intval($this->BuyableID)."
         						AND \"Version\" = ".intval($this->Version)."
         				");
         				if($result->value()) {
         			 */
         $obj = OrderItem::get_version($this->BuyableClassName, $this->BuyableID, $this->Version);
     }
     //our last resort
     if (!$obj) {
         $obj = Versioned::get_latest_version($this->BuyableClassName, $this->BuyableID);
     }
     if ($turnTranslatableBackOn) {
         Translatable::enable_locale_filter();
     }
     return $obj;
 }
 /**
  *
  * @param Boolean $current - is this a current one, or an older VERSION ?
  * @return DataObject (Any type of Data Object that is buyable)
  **/
 function Buyable($current = false)
 {
     $tempBuyableStoreType = $current ? "current" : "version";
     if (!isset($this->tempBuyableStore[$tempBuyableStoreType])) {
         if (!$this->BuyableID) {
             user_error("There was an error retrieving the product", E_USER_NOTICE);
             return null;
         }
         //start hack
         if (!$this->BuyableClassName) {
             $this->BuyableClassName = str_replace("_OrderItem", "", $this->ClassName);
         }
         $turnTranslatableBackOn = false;
         $className = $this->BuyableClassName;
         if ($className::has_extension($this->class, 'Translatable')) {
             Translatable::disable_locale_filter();
             $turnTranslatableBackOn = true;
         }
         //end hack!
         $obj = null;
         if ($current) {
             $obj = $className::get()->byID($this->BuyableID);
         }
         //run if current not available or current = false
         if (!$obj || !$current) {
             if ((!$obj || !$obj->exists()) && $this->Version) {
                 /* @TODO: check if the version exists?? - see sample below
                 			$versionTable = $this->BuyableClassName."_versions";
                 			$dbConnection = DB::getConn();
                 			if($dbConnection && $dbConnection instanceOf MySQLDatabase && $dbConnection->hasTable($versionTable)) {
                 				$result = DB::query("
                 					SELECT COUNT(\"ID\")
                 					FROM \"$versionTable\"
                 					WHERE
                 						\"RecordID\" = ".intval($this->BuyableID)."
                 						AND \"Version\" = ".intval($this->Version)."
                 				");
                 				if($result->value()) {
                 			 */
                 $obj = OrderItem::get_version($this->BuyableClassName, $this->BuyableID, $this->Version);
             }
             //our second to last resort
             if (!$obj || !$obj->exists()) {
                 $obj = Versioned::get_latest_version($this->BuyableClassName, $this->BuyableID);
             }
         }
         //our final backup
         if (!$obj || !$obj->exists()) {
             $obj = $className::get()->byID($this->BuyableID);
         }
         if ($turnTranslatableBackOn) {
             Translatable::enable_locale_filter();
         }
         $this->tempBuyableStore[$tempBuyableStoreType] = $obj;
     }
     return $this->tempBuyableStore[$tempBuyableStoreType];
 }