Skip to content

Instantly share code, notes, and snippets.

View zsy715's full-sized avatar

Shengyang zsy715

View GitHub Profile
@zsy715
zsy715 / BBMS_EMAIL.md
Last active January 28, 2019 22:40
all repos are potentially using BBMS to send email
@zsy715
zsy715 / magento_braze_event.md
Last active April 18, 2019 16:47
Braze event in magento

Braze Usertrack Events in Magento

Recently, Birchbox moved non-transactional emails from Selligent to Braze(tech doc). This page is mainly a quick reference of braze events being sent within Magento.
All Braze configurations(endpoint url, api key, threshold etc) could be found in magento admin UI. They are under System -> Configuration -> Birchbox APIs.
relevant code is here

Braze event post helper

In Magento, there is a helper class(EventPost.php) which includes all the fundamental methods(read configurations, send post request to Braze endpoint) for braze event post.
Any further implementations should also go to this class to avoid duplicated code.

There are a couple of Braze user tra

@zsy715
zsy715 / user_api_braze_event.md
Last active April 18, 2019 14:40
Beauty/Grooming profile update event

Braze user track event in USER_API

Event post helper class

braze.rb contains basic functionalities to interact with Braze endpoint.
Currently, we only include UserTracker module/class.

Beuty/Grooming update event: code

On beauty/grooming profile page, everytime user selects different option will trigger a request to update her/his profile. Right after new profile is updated, a post request to Braze user track endpoint will also be sent.

payload:

OHL_GET script explore notes:

External scripts/end point:

  • INC_ENDPOINT = "og/src/main/php/com/birchbox/og/cli/dotcom/DotcomCLI.php" (by post_inventory_increment)
  • DEC_ENDPOINT = "_birchboxadmin/logistics/decrement_inventorycountCLI.php"(by post_inventory_decrement)
  • tools server:
    ohl_item_master - https://{tools-server}/api/ohl_item_master
    rc-file-importer - https://{tools-server}/api/rc-file-importer
  • erp_integration: etl_pass.py
  • DME: ./run.sh us (-s) -t CSH****

RAF codes have been already created in referral_code table(I guess it's created along with new account)

Both referral and nudge email are sent by magento via cron job:

  • Refering a Friend
  • code:
  • cron: REFERRAL_EMAIL_TEMPLATE_ID
    ADVENT_EMAIL_TEMPLATE_ID we have referral invitation without email template id since 2017/12/13 last time we sent raf_code='__advent' is 2017/12/13

DME shipment file import process:

  • import line by line
  • get shipment by incrementId(order id lie BB*****)
    • run query Select * from birchbox_shipment_history WHERE increment_id =
    • shoud return shipment, tracking number should be empty and status should be processing
  • update shipment
    • run query
        UPDATE birchbox_shipment_history SET status = 'completed', 
            shipped_at = NOW(),
curl https://tools.team.birchbox.com/api/pim/products/product_or_sample_by_upcs?upc=838760000035

PIM/Products:

  • the page shows Product Attribute View which is mainly from a view pim_product_attributes_view. The view does a bunch of table join. The drawback of it is there is no way for us to utilize index to speed up querying. The view does provide very details of product attribute but I don’t think in PIM/Products page, we utilize most of them. The attributes we currently care about are vendor name, product name, vendor sku, magento id, category department, category class, category subclass, unique_id and status. These attributes are what we list on the page and we performance search function against them as well.
  • One potential solution is manually join necessary tables so that we can optimize the query by using indexes instead of reading entries from the view. Also, we can eager load tables to avoid N+1 query which is not a major issue regarding to the performance.
  • some tests against sql with necessary tables joined together.

origin sql:

SELECT vendor_name, name, cat_department, cat_cl

The result of my investigation:

  • the update/create method in the backend is pretty straight forward. Since a product is associated with multiple attributes, every time in order to create/update product, all the attributes need to be created/updated which take some reasonable time(4s-5s). I think the issue is after update the product, page would be redirected to /pim/products page. This is the page where we could do some optimization. In my dev, to load this page would cause 6s
  • another thing could be improved is edit/new product page loading time. Currently, without eager loading attributes, the page takes 7.5+s to load. With some eager load tweaks, the time could drop to 4.5s. The page load could be cut off 3s.
  • in bbop-orders, some logs shows no shipping method. In the code, if no shipping method, order won't be forwarded to bbop-shipments
15:36:41.060 [pool-2-thread-151] WARN  ?.(:): Order complete with included items but no shipping method: 129665819
15:37:49.335 [pool-2-thread-54] WARN  ?.(:): Order complete with included items but no shipping method: 129665835
15:38:06.454 [pool-2-thread-127] WARN  ?.(:): Order complete with included items but no shipping method: 129665837
15:41:40.352 [pool-2-thread-110] WARN  ?.(:): Order complete with included items but no shipping method: 129665871
15:42:25.285 [pool-2-thread-139] WARN  ?.(:): Order complete with included items but no shipping method: 129665879
15:43:05.041 [pool-2-thread-104] WARN  ?.(:): Order complete with included items but no shipping method: 129665886
15:43:20.865 [pool-2-thread-36] WARN  ?.(:): Order complete with included items but no shipping method: 129665889
15:45:33.296 [pool-2-thread-169] WARN  ?.(:): Order complete with included items but