Skip to content

Instantly share code, notes, and snippets.

@jimarnold
Created February 24, 2022 22:04
Show Gist options
  • Save jimarnold/f2b7b390cc5d40b96a83bcd4b894804f to your computer and use it in GitHub Desktop.
Save jimarnold/f2b7b390cc5d40b96a83bcd4b894804f to your computer and use it in GitHub Desktop.
diff --git a/phplib/Atlas/Recsys/BuyerHub/ApiSpecs/Index.php b/phplib/Atlas/Recsys/BuyerHub/ApiSpecs/Index.php
index 840b5d2b7c76..29e4405f3286 100644
--- a/phplib/Atlas/Recsys/BuyerHub/ApiSpecs/Index.php
+++ b/phplib/Atlas/Recsys/BuyerHub/ApiSpecs/Index.php
@@ -4,13 +4,18 @@
class Atlas_Recsys_BuyerHub_ApiSpecs_Index implements Neu_Api_Spec_IHash {
use Neu_Api_Spec_Hash;
const REF_TAG = 'buyer_hub_ref_tag';
+ /**
+ * @var array
+ */
+ private $user_data;
/**
* @var int $user_id
*/
private $user_id;
- public function __construct() {
+ public function __construct(array $user_data) {
+ $this->user_data = $user_data;
$request = $request = HTTP_Request::getInstance();
$this->user_id = (int)($request->getGet('user_id', null) ?? $request->user()->user_id);
}
@@ -30,6 +35,6 @@ public function getOwnProxies(Api_Client $client): array {
public function getCompositeView(array $views, array $response_bodies, array $response_proxies): Atlas_Recsys_BuyerHub_Views_Index {
$user_id = $response_bodies[Neu_Api_Spec_IHash::OWN_KEY]['user']->user_id;
- return new Atlas_Recsys_BuyerHub_Views_Index($user_id, $views);
+ return new Atlas_Recsys_BuyerHub_Views_Index($user_id, $views, $this->user_data);
}
}
diff --git a/phplib/Atlas/Recsys/BuyerHub/Controller.php b/phplib/Atlas/Recsys/BuyerHub/Controller.php
index f8d54b7637ed..0cc92d6dd651 100644
--- a/phplib/Atlas/Recsys/BuyerHub/Controller.php
+++ b/phplib/Atlas/Recsys/BuyerHub/Controller.php
@@ -5,8 +5,30 @@ class Atlas_Recsys_BuyerHub_Controller implements Neu_Controller {
use Neu_Traits_BareRenderer;
public function handle(HTTP_Request $request, HTTP_Response $response) {
+ $user = HTTP_Request::getInstance()->user();
+ $user_id = $user->user_id;
+ $buyerSegmentFinder = EtsyORM::getFinder('User_BuyerSegment');
+ $segmentRecord = $buyerSegmentFinder->findRecord($user_id);
+ if (isset($segmentRecord)) {
+ $buyer_segment = $segmentRecord->buyer_segment_name;
+ } else {
+ $buyer_segment = "Buyer Segment Not Found";
+ }
+ $region = $user->getLocalePreference(EP_Locale_Helper::REGION_PREF_NAME);
+ $receipt_finder = EtsyORM::getFinder('Shop_Receipt2');
+ $collection_finder = EtsyORM::getFinder('ListingSet_Collection');
+ $collections = $collection_finder->findActiveByUser($user);
+
+ $user_data = [
+ 'buyer_segment' => $buyer_segment,
+ 'region' => $region,
+ 'purchases' => $user->UserDetails()->transaction_buy_count,
+ 'orders' => (int)$receipt_finder->countAllReceiptsBySellerUserID($user_id)['all'],
+ 'favorites' => $user->UserDetails()->favoritelistings_count,
+ 'collections' => count($collections),
+ ];
$api_specs = Neu_Api_Specs::atlas(__CLASS__, [
- 'buyer_hub_index' => new Atlas_Recsys_BuyerHub_ApiSpecs_Index(),
+ 'buyer_hub_index' => new Atlas_Recsys_BuyerHub_ApiSpecs_Index($user_data),
]);
$main_view = $api_specs->getView('buyer_hub_index');
$this->renderView($main_view);
diff --git a/phplib/Atlas/Recsys/BuyerHub/Views/Index.php b/phplib/Atlas/Recsys/BuyerHub/Views/Index.php
index 7864e4a36a80..2c0c19af4186 100644
--- a/phplib/Atlas/Recsys/BuyerHub/Views/Index.php
+++ b/phplib/Atlas/Recsys/BuyerHub/Views/Index.php
@@ -14,10 +14,15 @@ class Atlas_Recsys_BuyerHub_Views_Index implements Neu_View {
* @var int
*/
private $user_id;
+ /**
+ * @var array
+ */
+ private $user_data;
- public function __construct(int $user_id, array $views) {
+ public function __construct(int $user_id, array $views, array $user_data) {
$this->user_id = $user_id;
$this->views = $views;
+ $this->user_data = $user_data;
}
public function getRegionMap(): array {
@@ -26,7 +31,8 @@ public function getRegionMap(): array {
public function getTemplateData(): array {
return [
- 'user_id' => $this->user_id
+ 'user_id' => $this->user_id,
+ 'user_data' => $this->user_data,
];
}
diff --git a/phplib/Atlas/Recsys/BuyerHub/Views/ListingCardGrid.php b/phplib/Atlas/Recsys/BuyerHub/Views/ListingCardGrid.php
index 7426a2facef7..50132f64dfbe 100644
--- a/phplib/Atlas/Recsys/BuyerHub/Views/ListingCardGrid.php
+++ b/phplib/Atlas/Recsys/BuyerHub/Views/ListingCardGrid.php
@@ -30,6 +30,11 @@ public function __construct(array $listing_cards, string $title, array $subtexts
public function getRegionMap(): array {
$options = NeuViews_Formatter_ListingCard_Options::getDefaultOptions();
+ $options->hide_rating = true;
+ $options->hide_shop_name = true;
+ $options->badges_disabled = true;
+ $options->hide_free_shipping = true;
+ $options->hide_favorite_heart = true;
$options_map = NeuViews_Formatter_ListingCard_Options::getOptionsWithIndexedRefTag(
$this->listing_cards,
$options,
diff --git a/templates/atlas/recsys/buyer_hub/app.mustache b/templates/atlas/recsys/buyer_hub/app.mustache
index 3c721e407bd0..ba523ecbae60 100644
--- a/templates/atlas/recsys/buyer_hub/app.mustache
+++ b/templates/atlas/recsys/buyer_hub/app.mustache
@@ -18,5 +18,13 @@
</div>
<div id="content" class="ui-toolkit wt-bg-white wt-pl-xs-4 wt-pt-xs-4 wt-pr-xs-4 wt-body-max-width">
<h3 class="wt-text-heading-02 wt-mb-xs-4">User #{{user_id}}</h3>
+ <ul class="wt-list wt-mb-xs-4">
+ <li class="wt-list-inline__item">{{user_data.buyer_segment}} buyer</li>
+ <li class="wt-list-inline__item">{{user_data.region}}</li>
+ <li class="wt-list-inline__item">{{user_data.purchases}} Purchases</li>
+ <li class="wt-list-inline__item">{{user_data.orders}} Orders</li>
+ <li class="wt-list-inline__item">{{user_data.favorites}} Favorites</li>
+ <li class="wt-list-inline__item">{{user_data.collections}} Collections</li>
+ </ul>
<div>{{{regions.recommendations}}}</div>
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment