These are chat archives for reactioncommerce/reaction

4th
Aug 2015
Aaron Judd
@aaronjudd
Aug 04 2015 00:50
@spencern here’s an example:
_updateOrCreateUserFromExternalService = Accounts.updateOrCreateUserFromExternalService

Accounts.updateOrCreateUserFromExternalService = (serviceName, serviceData, options) ->
   do stuff.. here
   then call original:
  _updateOrCreateUserFromExternalService.apply this, arguments
Bogi
@boboci9
Aug 04 2015 11:10
Hi all, I have an interesting issue, I have registered a global helper in one of my helper files and I have an issue with the ReactionCore.shopId or ReactionCore.getShopId() both being null when the helper is called
Is there any solution to force the helper to be called after ReactionCore init? or do you know any other approach?
Bogi
@boboci9
Aug 04 2015 13:46
Never mind I found a work around :) thanks anyways
Spencer Norman
@spencern
Aug 04 2015 13:46
@aaronjudd can I do this with a Meteor.method
Aaron Judd
@aaronjudd
Aug 04 2015 13:48
@boboci9 ( Tracker.autorun?)
@spencern I think so, it didn't work?
Spencer Norman
@spencern
Aug 04 2015 13:50
It didn't. If I use Meteor.method.createVariant =... For example it didn't change the method ata
at all.
And if I try to re declare, within Meteor.methods then it errors with method already exists
Quite possible I'm not doing it right though
Aaron Judd
@aaronjudd
Aug 04 2015 13:52
no, I was thinking general meteor functions, not specifically meteor.method - my bad, sorrry
but I'm also sure there's some hints on directly extending/overriding the methods in the code somewhere there - I know you can, just don't remember the syntax
Spencer Norman
@spencern
Aug 04 2015 13:58
I’ll check that out.
Aaron Judd
@aaronjudd
Aug 04 2015 13:58
look in his code, you'll see: Meteor.server.method_handlers[method]
that's the actual method to extend/override
Spencer Norman
@spencern
Aug 04 2015 13:59
We are using this package in reaction-core already I’m guessing?
Aaron Judd
@aaronjudd
Aug 04 2015 14:00
I'm not - but I've been considering something like this - I just haven't sat down and thought about the best way to add hooks
Spencer Norman
@spencern
Aug 04 2015 14:01
I see, pretty simple implementation it seems.
Aaron Judd
@aaronjudd
Aug 04 2015 14:03
let me know how it works, we could add some similar setup to core
Spencer Norman
@spencern
Aug 04 2015 14:03
ok
Spencer Norman
@spencern
Aug 04 2015 15:05
so I can use method hooks to do something before or after a core method call from within another package
Aaron Judd
@aaronjudd
Aug 04 2015 15:06
is that good enough? or do you need to replace entirely?
Spencer Norman
@spencern
Aug 04 2015 15:06
But I’m trying to mutate a parameter of a method
Meteor.beforeMethods 'createVariant', (productId, newVariant) ->
  newVariantId = Random.id()
  if newVariant
    newVariant._id = newVariantId
    newVariant.title = newVariant.title || ''
    newVariant.price = newVariant.price || 0.00
    newVariant.pricePerDay = newVariant.pricePerDay || 0.00
    newVariant.pricePerWeek = newVariant.pricePerWeek || 0.00
    newVariant.type = newVariant.type || 'rentalVariant'
    newVariant.events = newVariant.events || []
    check(newVariant, ReactionCore.Schemas.RentalProductVariant)
  else
    newVariant =
      '_id': newVariantId
      'active': true
      'title': ''
      'price': 0.00
      'pricePerDay': 0.00
      'pricePerWeek': 0.00
      'type': 'rentalVariant'
      events: []

  Meteor.call 'createVariant', productId, newVariant

  return false
If I do something like this, it enters an infinite loop because my internal call to ‘createVariant’ causes the beforeMethod to trigger again
I can’t seem to figure out how to change the newVariant object or add fields to it within this method
I guess I could potentially call a different method from within this method
and then return false to cancel the original method
but it feels pretty dirty
And it won’t return the created variant._id which is important
Aaron Judd
@aaronjudd
Aug 04 2015 15:11
stepping back a bit, newVariant is meant to be for you to pass a custom variant to when you call createVariant - that doesn’t work for you?
Spencer Norman
@spencern
Aug 04 2015 15:12
That works fine. Maybe I’m overthinking this,
What I was originally trying to do was to ensure that when createVariant was called (which is only on the initial product creation, everything after that is cloneVariant) that it had all of the necessary fields in the schema so that my package could depend on certain fields existing
Aaron Judd
@aaronjudd
Aug 04 2015 15:15
look at the top of the hooks.coffee file for variant defaults
might be a clue
Spencer Norman
@spencern
Aug 04 2015 15:16
That’s good to know
Aaron Judd
@aaronjudd
Aug 04 2015 15:16
those are easily forgotten....
Spencer Norman
@spencern
Aug 04 2015 15:17
Yeah, definitely forgot about those..
Spencer Norman
@spencern
Aug 04 2015 16:54
I have a few random bug fixes and code cleanups that came up while working through this for core. Should I submit them as individual PRs or a single PR?
Aaron Judd
@aaronjudd
Aug 04 2015 20:35
I think I'd prefer individual PR's but I'll take them anyway you want to deliver them. Individual PR's are smaller / easier to verify handle so I can usually merge them quickly.