Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added
add-to-cart-dedicated
, added Product and Purchase cart models (…
…#99) * Added `add-to-cart-dedicated`, added Product and Purchase cart models * Added new attributes to Osimage model * Added ability added to cart dedicated server * minor
- Loading branch information
Showing
12 changed files
with
437 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace hipanel\modules\server\cart; | ||
|
||
use hipanel\base\ModelTrait; | ||
use hipanel\modules\finance\cart\Calculation; | ||
|
||
|
||
class ConfigCalculation extends Calculation | ||
{ | ||
use ModelTrait; | ||
|
||
/** {@inheritdoc} */ | ||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
$this->object = 'serverConfig'; | ||
$this->type = 'purchase'; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function rules() | ||
{ | ||
return array_merge(parent::rules(), [ | ||
[['object_id'], 'integer'], | ||
[['location'], 'string'], | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,183 @@ | ||
<?php | ||
/** | ||
* Server module for HiPanel | ||
* | ||
* @link https://github.com/hiqdev/hipanel-module-server | ||
* @package hipanel-module-server | ||
* @license BSD-3-Clause | ||
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) | ||
*/ | ||
|
||
namespace hipanel\modules\server\cart; | ||
|
||
use hipanel\modules\server\models\Config; | ||
use hipanel\modules\server\models\Osimage; | ||
use hipanel\modules\server\models\Package; | ||
use hipanel\modules\server\widgets\cart\OrderPositionDescriptionWidget; | ||
use Yii; | ||
use yii\helpers\ArrayHelper; | ||
|
||
class ServerOrderDedicatedProduct extends AbstractServerProduct | ||
{ | ||
/** {@inheritdoc} */ | ||
protected $_purchaseModel = ServerOrderDedicatedPurchase::class; | ||
|
||
/** @var Package */ | ||
protected $_model; | ||
|
||
/** {@inheritdoc} */ | ||
protected $_calculationModel = ConfigCalculation::class; | ||
|
||
/** | ||
* @var Osimage the selected OS image detailed information | ||
*/ | ||
protected $_image; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $location; | ||
|
||
/** | ||
* @var integer | ||
*/ | ||
public $object_id; | ||
|
||
/** | ||
* @var integer | ||
*/ | ||
public $tariff_id; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
public $label; | ||
|
||
/** | ||
* @var string link to any kind of social network | ||
*/ | ||
public $administration; | ||
|
||
/** | ||
* @var string osimage name. Is used to load [[_image]] on product initialisation | ||
*/ | ||
public $osimage; | ||
|
||
/** | ||
* @var string software package name | ||
*/ | ||
public $softpack; | ||
|
||
/** {@inheritdoc} */ | ||
public function load($data, $formName = null) | ||
{ | ||
if ($result = parent::load($data, '')) { | ||
$this->ensureRelatedData(); | ||
} | ||
|
||
return $result; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
private function ensureRelatedData() | ||
{ | ||
$this->_model = Config::findOne($this->object_id); | ||
$this->_image = Osimage::find()->where(['osimage' => $this->osimage, 'type' => 'dedicated'])->one(); | ||
$this->name = $this->_model->name; | ||
$this->description = $this->_model->descr; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function getId() | ||
{ | ||
if ($this->_id === null) { | ||
$this->_id = hash('crc32b', implode('_', ['server', 'order', 'dedicated', $this->_model->id])); | ||
} | ||
|
||
return $this->_id; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function getCalculationModel($options = []) | ||
{ | ||
return parent::getCalculationModel(array_merge([ | ||
'tariff_id' => $this->tariff_id, | ||
'object_id' => $this->object_id, | ||
'location' => $this->location, | ||
], $options)); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function getPurchaseModel($options = []) | ||
{ | ||
$this->ensureRelatedData(); | ||
|
||
$options = array_merge([ | ||
'osimage' => $this->osimage, | ||
'object_id' => $this->object_id, | ||
'label' => $this->label, | ||
'administration' => $this->administration, | ||
'softpack' => $this->softpack, | ||
'tariff_id' => $this->tariff_id, | ||
], $options); | ||
|
||
return parent::getPurchaseModel($options); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function rules() | ||
{ | ||
return array_merge(parent::rules(), [ | ||
[['object_id', 'tariff_id'], 'integer'], | ||
[['administration', 'osimage', 'label', 'location'], 'string'], | ||
[['tariff_id', 'object_id', 'osimage', 'location'], 'required'], | ||
]); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function attributeLabels() | ||
{ | ||
return ArrayHelper::merge(parent::attributeLabels(), [ | ||
'object_id' => Yii::t('hipanel:server:order', 'Server config'), | ||
'label' => Yii::t('hipanel:server:order', 'Label'), | ||
]); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function attributeHints() | ||
{ | ||
return ArrayHelper::merge(parent::attributeHints(), [ | ||
'label' => Yii::t('hipanel:server:order', 'How are you going to use the server?'), | ||
'administration' => Yii::t('hipanel:server:order', 'Any social network link. Will be used in case of emergency contact'), | ||
]); | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function renderDescription() | ||
{ | ||
return OrderPositionDescriptionWidget::widget(['position' => $this]); | ||
} | ||
|
||
/** | ||
* @return Osimage | ||
*/ | ||
public function getImage() | ||
{ | ||
return $this->_image; | ||
} | ||
|
||
protected function serializationMap() | ||
{ | ||
$parent = parent::serializationMap(); | ||
$parent['object_id'] = $this->object_id; | ||
$parent['osimage'] = $this->osimage; | ||
$parent['label'] = $this->label; | ||
$parent['administration'] = $this->administration; | ||
$parent['softpack'] = $this->softpack; | ||
$parent['tariff_id'] = $this->tariff_id; | ||
$parent['location'] = $this->location; | ||
$parent['_image'] = $this->_image; | ||
|
||
return $parent; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
/** | ||
* Server module for HiPanel | ||
* | ||
* @link https://github.com/hiqdev/hipanel-module-server | ||
* @package hipanel-module-server | ||
* @license BSD-3-Clause | ||
* @copyright Copyright (c) 2015-2019, HiQDev (http://hiqdev.com/) | ||
*/ | ||
|
||
namespace hipanel\modules\server\cart; | ||
|
||
use hipanel\base\ModelTrait; | ||
use hipanel\modules\finance\cart\PendingPurchaseException; | ||
use hipanel\widgets\Box; | ||
use Yii; | ||
|
||
/** | ||
* Class ServerOrderPurchase. | ||
*/ | ||
class ServerOrderDedicatedPurchase extends AbstractServerPurchase | ||
{ | ||
use ModelTrait; | ||
|
||
/** {@inheritdoc} */ | ||
public static function operation() | ||
{ | ||
return 'Buy'; | ||
} | ||
|
||
/** {@inheritdoc} */ | ||
public function init() | ||
{ | ||
parent::init(); | ||
|
||
$this->amount = $this->position->getQuantity(); | ||
} | ||
|
||
public function rules() | ||
{ | ||
return array_merge(parent::rules(), [ | ||
[['osimage', 'config_id', 'tariff_id'], 'required'], | ||
[['osimage', 'administration', 'softpack', 'label', 'location'], 'string'], | ||
[['tariff_id', 'object_id'], 'integer'], | ||
]); | ||
} | ||
|
||
public function execute() | ||
{ | ||
if (parent::execute()) { | ||
$remark = Box::widget([ | ||
'options' => ['class' => 'box-solid box-warning'], | ||
'body' => Yii::t('hipanel:server:order', 'You will receive an email with server access information right after setup'), | ||
]); | ||
|
||
Yii::$app->getView()->params['remarks'][__CLASS__] = $remark; | ||
|
||
if (is_array($this->_result) && isset($this->_result['_action_pending'])) { | ||
throw new PendingPurchaseException(Yii::t('hipanel:server:order', 'Server setup will be performed as soon as manager confirms your account verification. Pleas wait.'), $this); | ||
} | ||
|
||
return true; | ||
} | ||
|
||
return false; | ||
} | ||
|
||
public function renderNotes() | ||
{ | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.