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

feat: Automatically create a product on new membership creation

Übergeordneter d0e8925d
No related branches found
No related tags found
Keine zugehörigen Merge Requests gefunden
......@@ -13,8 +13,7 @@
QUI::$Ajax->registerFunction(
'package_quiqqer_memberships_ajax_memberships_getInstalledMembershipPackages',
function () {
$Memberships = new MembershipsHandler();
return $Memberships->getInstalledMembershipPackages();
return MembershipsHandler::getInstalledMembershipPackages();
},
array(),
'Permission::checkAdminUser'
......
......@@ -29,7 +29,7 @@ public static function onPackageSetup(Package $Package)
return;
}
$packages = MembershipsHandler::getInstance()->getInstalledMembershipPackages();
$packages = MembershipsHandler::getInstalledMembershipPackages();
foreach ($packages as $package) {
switch ($package) {
......@@ -69,13 +69,15 @@ protected static function createProductField()
}
try {
ProductFields::createField(array(
$NewField = ProductFields::createField(array(
'id' => MembershipField::FIELD_ID,
'type' => MembershipField::TYPE,
'titles' => $translations,
'workingtitles' => $translations,
'search_type' => ProductSearchHandler::SEARCHTYPE_TEXT
'workingtitles' => $translations
));
$NewField->setAttribute('search_type', ProductSearchHandler::SEARCHTYPE_TEXT);
$NewField->save();
} catch (\QUI\ERP\Products\Field\Exception $Exception) {
// nothing, field exists
} catch (\Exception $Exception) {
......
......@@ -67,7 +67,11 @@ public function createChild($data = array())
$data['groupIds'] = ',' . implode(',', $groupIds) . ',';
$data['duration'] = '1-month';
return parent::createChild($data);
/** @var Membership $NewMembership */
$NewMembership = parent::createChild($data);
$NewMembership->createProduct();
return $NewMembership;
}
/**
......@@ -188,7 +192,7 @@ public function search($searchParams, $countOnly = false)
*
* @return array
*/
public function getInstalledMembershipPackages()
public static function getInstalledMembershipPackages()
{
$packages = array();
$relevantPackages = array(
......
......@@ -431,12 +431,16 @@ public function calcEndDate($start = null)
*/
public function getProducts()
{
if (!in_array('quiqqer/products', Handler::getInstalledMembershipPackages())) {
return array();
}
$Search = new BackendSearch();
try {
$result = $Search->search(array(
'fields' => array(
MembershipField::FIELD_ID => $this->id
MembershipField::FIELD_ID => "$this->id"
)
));
} catch (QUI\Permissions\Exception $Exception) {
......@@ -460,10 +464,14 @@ public function getProducts()
* Hint: Every time this method is called, a new Product is created, regardless
* of previous calls!
*
* @return QUI\ERP\Products\Product\Product
* @return QUI\ERP\Products\Product\Product|false
*/
public function createProduct()
{
if (!in_array('quiqqer/products', Handler::getInstalledMembershipPackages())) {
return false;
}
$categories = array();
$fields = array();
......
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