-
-
Notifications
You must be signed in to change notification settings - Fork 824
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[REF] Update Product Create to use hooks and also switch the manage p… #20822
[REF] Update Product Create to use hooks and also switch the manage p… #20822
Conversation
(Standard links)
|
@@ -291,10 +292,16 @@ public function postProcess() { | |||
$this->_processImages($params); | |||
|
|||
// Save the premium product to database | |||
$premium = CRM_Contribute_BAO_Product::create($params); | |||
// If we're updating, we need to pass in the premium product Id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually you don't. APIv4::update
doesn't require a where
param if $values
contains an id
:)
if ($this->_action & CRM_Core_Action::UPDATE) { | ||
$premium = Product::update(FALSE)->setValues($params)->addWhere('id', '=', $this->_id)->execute()->first(); | ||
} | ||
else { | ||
$premium = Product::create(FALSE)->setValues($params)->execute()->first(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you could just turn these 6 lines into a 1-liner by using
if ($this->_action & CRM_Core_Action::UPDATE) { | |
$premium = Product::update(FALSE)->setValues($params)->addWhere('id', '=', $this->_id)->execute()->first(); | |
} | |
else { | |
$premium = Product::create(FALSE)->setValues($params)->execute()->first(); | |
} | |
$premium = Product::save(FALSE)->addRecord($params)->execute()->first(); |
Thanks @colemanw I have committed your suggestion now |
a9cee0d
to
5edd001
Compare
@colemanw is this all good now? |
@@ -35,8 +37,7 @@ public function getDefaultEntity() { | |||
public function setDefaultValues() { | |||
$defaults = parent::setDefaultValues(); | |||
if ($this->_id) { | |||
$params = ['id' => $this->_id]; | |||
CRM_Contribute_BAO_Product::retrieve($params, $tempDefaults); | |||
$tempDefaults = Product::get(FALSE)->addWhere('id', '=', $this->_id)->execute()->first(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@seamuslee001 I'm just looking at you putting check permissions to FALSE. This is one of those places where ideally we WOULD have permissions kick in - ie this seems to be the form to configure products & hence the ability to get & save products should be material. I can think of 2 reasons why you put FALSE here
- habit
- our permissions for product are too tight & it failed without bypassing them
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok @eileenmcnaughton I have changed this to not override check permissions now and have updated the entity permissions so that product matches contribution which seems to be the most accurate thing here IMO
…roduct/premium page to use APIv4 Product Entity Update to use suggestion from Coleman Set Product permissions to be the same as contribution entity
5edd001
to
7e49aa9
Compare
@@ -90,7 +91,7 @@ public static function create($params) { | |||
]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is a pre-existing condition and not a blocker for this PR, but I really hate this array of defaults. They should be set in the schema. Also, is_active
should default to TRUE for consistency with every other entity.
I'm OK with merging this as-is, but I'd push for an additional cleanup of deprecating this |
…roduct/premium page to use APIv4 Product Entity
Overview
This updates the Product create BAO to trigger pre/post hooks and also to update the Manage Product forms to use the newly added v4 API entity
Before
No hooks triggered and DAO used
After
Hooks triggered and APIv4 Entity used
ping @colemanw @demeritcowboy @eileenmcnaughton @totten