Skip to content
Code-Schnipsel Gruppen Projekte
Commit 24a6e31b erstellt von Patrick Müller's avatar Patrick Müller
Dateien durchsuchen

feat: automatically set contract fields to a product created by a Membership

Übergeordneter 8680df75
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -361,7 +361,7 @@ public static function getProductCategory()
*
* Get quiqqer/products membership Field
*
* @return QUI\ERP\Products\Interfaces\FieldInterface|false
* @return QUI\ERP\Products\Field\Field|false
*/
public static function getProductMembershipField()
{
......@@ -389,7 +389,7 @@ public static function getProductMembershipField()
*
* Get quiqqer/products membership flag Field
*
* @return QUI\ERP\Products\Interfaces\FieldInterface|false
* @return QUI\ERP\Products\Field\Field|false
*/
public static function getProductMembershipFlagField()
{
......
......@@ -11,9 +11,9 @@
use QUI\Permissions\Permission;
use QUI\Utils\Security\Orthos;
use QUI\ERP\Products\Search\BackendSearch;
use QUI\Memberships\Products\MembershipField;
use QUI\ERP\Products\Handler\Products as ProductsHandler;
use QUI\ERP\Products\Handler\Fields as ProductFields;
use QUI\ERP\Plans\Handler as ErpPlansHandler;
class Membership extends Child
{
......@@ -536,6 +536,7 @@ public function createProduct()
$MembershipField = Handler::getProductMembershipField();
if ($MembershipField !== false) {
$MembershipField->setOwnFieldStatus(true);
$MembershipField->setValue($this->id);
$fields[] = $MembershipField;
}
......@@ -543,6 +544,7 @@ public function createProduct()
$MembershipFlagField = Handler::getProductMembershipFlagField();
if ($MembershipFlagField !== false) {
$MembershipFlagField->setOwnFieldStatus(true);
$MembershipFlagField->setValue(true);
$fields[] = $MembershipFlagField;
}
......@@ -563,6 +565,31 @@ public function createProduct()
$fields[] = $DescField;
}
// Add fields for contract product type
if (Utils::isQuiqqerErpPlansInstalled()) {
$planFields = ErpPlansHandler::getPlanProductFields();
foreach ($planFields as $Field) {
try {
$Field->setOwnFieldStatus(true);
switch ($Field->getId()) {
case ErpPlansHandler::FIELD_DURATION:
$Field->setValue($this->getAttribute('duration'));
break;
case ErpPlansHandler::FIELD_AUTO_EXTEND:
$Field->setValue($this->isAutoExtend());
break;
}
$fields[] = $Field;
} catch (\Exception $Exception) {
QUI\System\Log::writeException($Exception);
}
}
}
$Product = ProductsHandler::createProduct($categories, $fields);
if (!empty($categories)) {
......
......@@ -85,7 +85,8 @@ public static function getInstalledMembershipPackages()
$packages = array();
$relevantPackages = array(
'quiqqer/products',
'quiqqer/contracts'
'quiqqer/contracts',
'quiqqer/erp-plans'
);
foreach ($relevantPackages as $package) {
......@@ -107,7 +108,17 @@ public static function getInstalledMembershipPackages()
*/
public static function isQuiqqerProductsInstalled()
{
return in_array('quiqqer/products', self::getInstalledMembershipPackages());
return QUI::getPackageManager()->isInstalled('quiqqer/products');
}
/**
* Check if quiqqer/erp-plans is installed
*
* @return bool
*/
public static function isQuiqqerErpPlansInstalled()
{
return QUI::getPackageManager()->isInstalled('quiqqer/erp-plans');
}
/**
......@@ -117,6 +128,6 @@ public static function isQuiqqerProductsInstalled()
*/
public static function isQuiqqerContractsInstalled()
{
return in_array('quiqqer/contracts', self::getInstalledMembershipPackages());
return QUI::getPackageManager()->isInstalled('quiqqer/contracts');
}
}
0% oder .
You are about to add 0 people to the discussion. Proceed with caution.
Bearbeitung dieser Nachricht zuerst beenden!
Bitte registrieren oder zum Kommentieren