@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Add "Carts" to Phortune

Summary: Although I imagine we aren't really going to have an "add to cart" type storefront, putting this in place makes a lot of other workflows simpler. No storage yet, just allows reasonable construction of a "buy stuff" page.

Test Plan: {F41342}

Reviewers: chad, btrahan

Reviewed By: chad

CC: aran

Maniphest Tasks: T2787

Differential Revision: https://secure.phabricator.com/D5745

+160 -13
+3 -1
src/__phutil_library_map__.php
··· 1580 1580 'PhortuneAccountTransaction' => 'applications/phortune/storage/PhortuneAccountTransaction.php', 1581 1581 'PhortuneAccountTransactionQuery' => 'applications/phortune/query/PhortuneAccountTransactionQuery.php', 1582 1582 'PhortuneAccountViewController' => 'applications/phortune/controller/PhortuneAccountViewController.php', 1583 + 'PhortuneCart' => 'applications/phortune/storage/PhortuneCart.php', 1583 1584 'PhortuneCharge' => 'applications/phortune/storage/PhortuneCharge.php', 1584 1585 'PhortuneController' => 'applications/phortune/controller/PhortuneController.php', 1585 1586 'PhortuneDAO' => 'applications/phortune/storage/PhortuneDAO.php', ··· 3293 3294 'PhortuneAccountTransaction' => 'PhabricatorApplicationTransaction', 3294 3295 'PhortuneAccountTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 3295 3296 'PhortuneAccountViewController' => 'PhortuneController', 3297 + 'PhortuneCart' => 'PhortuneDAO', 3296 3298 'PhortuneCharge' => 'PhortuneDAO', 3297 3299 'PhortuneController' => 'PhabricatorController', 3298 3300 'PhortuneDAO' => 'PhabricatorLiskDAO', ··· 3318 3320 'PhortuneProductQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 3319 3321 'PhortuneProductTransaction' => 'PhabricatorApplicationTransaction', 3320 3322 'PhortuneProductTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 3321 - 'PhortuneProductViewController' => 'PhabricatorController', 3323 + 'PhortuneProductViewController' => 'PhortuneController', 3322 3324 'PhortunePurchase' => 'PhortuneDAO', 3323 3325 'PhortuneStripePaymentFormView' => 'AphrontView', 3324 3326 'PhrequentController' => 'PhabricatorController',
+1
src/applications/phid/PhabricatorPHIDConstants.php
··· 38 38 const PHID_TYPE_PRCH = 'PRCH'; 39 39 const PHID_TYPE_PAYM = 'PAYM'; 40 40 const PHID_TYPE_CHRG = 'CHRG'; 41 + const PHID_TYPE_CART = 'CART'; 41 42 42 43 const PHID_TYPE_XACT = 'XACT'; 43 44 const PHID_TYPE_XCMT = 'XCMT';
+86 -10
src/applications/phortune/controller/PhortuneAccountBuyController.php
··· 33 33 return new Aphront404Response(); 34 34 } 35 35 36 - $title = pht('Buy %s', $product->getProductName()); 36 + $purchase = new PhortunePurchase(); 37 + $purchase->setProductPHID($product->getPHID()); 38 + $purchase->setAccountPHID($account->getPHID()); 39 + $purchase->setPurchaseName($product->getProductName()); 40 + $purchase->setBasePriceInCents($product->getPriceInCents()); 41 + $purchase->setQuantity(1); 42 + $purchase->setTotalPriceInCents( 43 + $purchase->getBasePriceInCents() * $purchase->getQuantity()); 44 + $purchase->setStatus(PhortunePurchase::STATUS_PENDING); 45 + 46 + $cart = new PhortuneCart(); 47 + $cart->setAccountPHID($account->getPHID()); 48 + $cart->setOwnerPHID($user->getPHID()); 49 + $cart->attachPurchases( 50 + array( 51 + $purchase, 52 + )); 53 + 54 + $rows = array(); 55 + $total = 0; 56 + foreach ($cart->getPurchases() as $purchase) { 57 + $rows[] = array( 58 + $purchase->getPurchaseName(), 59 + PhortuneUtil::formatCurrency($purchase->getBasePriceInCents()), 60 + $purchase->getQuantity(), 61 + PhortuneUtil::formatCurrency($purchase->getTotalPriceInCents()), 62 + ); 63 + 64 + $total += $purchase->getTotalPriceInCents(); 65 + } 66 + 67 + $rows[] = array( 68 + phutil_tag('strong', array(), pht('Total')), 69 + '', 70 + '', 71 + phutil_tag('strong', array(), PhortuneUtil::formatCurrency($total)), 72 + ); 73 + 74 + $table = new AphrontTableView($rows); 75 + $table->setHeaders( 76 + array( 77 + pht('Item'), 78 + pht('Price'), 79 + pht('Qty.'), 80 + pht('Total'), 81 + )); 82 + 83 + $panel = new AphrontPanelView(); 84 + $panel->setNoBackground(true); 85 + $panel->appendChild($table); 86 + 87 + 88 + $title = pht('Buy Stuff'); 89 + 90 + 91 + $methods = id(new PhortunePaymentMethodQuery()) 92 + ->setViewer($user) 93 + ->withAccountPHIDs(array($account->getPHID())) 94 + ->withStatus(PhortunePaymentMethodQuery::STATUS_OPEN) 95 + ->execute(); 96 + 97 + $method_control = id(new AphrontFormRadioButtonControl()) 98 + ->setLabel(pht('Payment Method')); 99 + 100 + if (!$methods) { 101 + $method_control = id(new AphrontFormStaticControl()) 102 + ->setLabel(pht('Payment Method')) 103 + ->setValue( 104 + phutil_tag('em', array(), pht('No payment methods configured.'))); 105 + } else { 106 + $method_control = id(new AphrontFormRadioButtonControl()) 107 + ->setLabel(pht('Payment Method')) 108 + ->setName('paymentMethodID') 109 + ->setValue($request->getInt('paymentMethodID')); 110 + foreach ($methods as $method) { 111 + $method_control->addButton( 112 + $method->getID(), 113 + $method->getName(), 114 + $method->getDescription()); 115 + } 116 + } 37 117 38 118 $payment_method_uri = $this->getApplicationURI( 39 119 $account->getID().'/paymentmethod/edit/'); ··· 46 126 ), 47 127 pht('Add New Payment Method')); 48 128 49 - 50 129 $form = id(new AphrontFormView()) 51 130 ->setUser($user) 52 - ->appendChild( 53 - id(new AphrontFormStaticControl()) 54 - ->setLabel(pht('Stuff')) 55 - ->setValue($product->getProductName())) 56 - ->appendChild( 57 - id(new AphrontFormRadioButtonControl()) 58 - ->setLabel(pht('Payment Method'))) 131 + ->appendChild($method_control) 59 132 ->appendChild( 60 133 id(new AphrontFormMarkupControl()) 61 134 ->setValue($new_method)) ··· 64 137 ->setValue(pht("Dolla Dolla Bill Y'all"))); 65 138 66 139 return $this->buildApplicationPage( 67 - $form, 140 + array( 141 + $panel, 142 + $form, 143 + ), 68 144 array( 69 145 'title' => $title, 70 146 'device' => true,
+15
src/applications/phortune/controller/PhortuneController.php
··· 2 2 3 3 abstract class PhortuneController extends PhabricatorController { 4 4 5 + protected function loadActiveAccount(PhabricatorUser $user) { 6 + $accounts = id(new PhortuneAccountQuery()) 7 + ->setViewer($user) 8 + ->withMemberPHIDs(array($user->getPHID())) 9 + ->execute(); 10 + 11 + if (!$accounts) { 12 + return $this->createUserAccount($user); 13 + } else if (count($accounts) == 1) { 14 + return head($accounts); 15 + } else { 16 + throw new Exception("TODO: No account selection yet."); 17 + } 18 + } 19 + 5 20 protected function createUserAccount(PhabricatorUser $user) { 6 21 $request = $this->getRequest(); 7 22
+13 -2
src/applications/phortune/controller/PhortuneProductViewController.php
··· 1 1 <?php 2 2 3 - final class PhortuneProductViewController extends PhabricatorController { 3 + final class PhortuneProductViewController extends PhortuneController { 4 4 5 5 private $productID; 6 6 ··· 26 26 $header = id(new PhabricatorHeaderView()) 27 27 ->setHeader($product->getProductName()); 28 28 29 + $account = $this->loadActiveAccount($user); 30 + 29 31 $edit_uri = $this->getApplicationURI('product/edit/'.$product->getID().'/'); 32 + $cart_uri = $this->getApplicationURI( 33 + $account->getID().'/buy/'.$product->getID().'/'); 30 34 31 35 $actions = id(new PhabricatorActionListView()) 32 36 ->setUser($user) ··· 34 38 id(new PhabricatorActionView()) 35 39 ->setName(pht('Edit Product')) 36 40 ->setHref($edit_uri) 37 - ->setIcon('edit')); 41 + ->setIcon('edit')) 42 + ->addAction( 43 + id(new PhabricatorActionView()) 44 + ->setUser($user) 45 + ->setName(pht('Purchase')) 46 + ->setHref($cart_uri) 47 + ->setIcon('new') 48 + ->setRenderAsForm(true)); 38 49 39 50 $crumbs = $this->buildApplicationCrumbs(); 40 51 $crumbs->setActionList($actions);
+38
src/applications/phortune/storage/PhortuneCart.php
··· 1 + <?php 2 + 3 + final class PhortuneCart extends PhortuneDAO { 4 + 5 + protected $accountPHID; 6 + protected $ownerPHID; 7 + protected $metadata; 8 + 9 + private $purchases; 10 + 11 + public function getConfiguration() { 12 + return array( 13 + self::CONFIG_AUX_PHID => true, 14 + self::CONFIG_SERIALIZATION => array( 15 + 'metadata' => self::SERIALIZATION_JSON, 16 + ), 17 + ) + parent::getConfiguration(); 18 + } 19 + 20 + public function generatePHID() { 21 + return PhabricatorPHID::generateNewPHID( 22 + PhabricatorPHIDConstants::PHID_TYPE_CART); 23 + } 24 + 25 + public function attachPurchases(array $purchases) { 26 + assert_instances_of($purchases, 'PhortunePurchase'); 27 + $this->purchases = $purchases; 28 + return $this; 29 + } 30 + 31 + public function getPurchases() { 32 + if ($this->purchases === null) { 33 + throw new Exception("Purchases not attached to cart!"); 34 + } 35 + return $this->purchases; 36 + } 37 + 38 + }
+4
src/applications/phortune/storage/PhortunePaymentMethod.php
··· 46 46 return $this->account; 47 47 } 48 48 49 + public function getDescription() { 50 + return pht('Expires %s', date('m/y'), $this->getExpiresEpoch()); 51 + } 52 + 49 53 50 54 /* -( PhabricatorPolicyInterface )----------------------------------------- */ 51 55