This repository has been archived by the owner on Apr 15, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 090d461
Showing
17 changed files
with
365 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
Commerce Friendly Order Numbers License | ||
(c) 2016 Jeremy Daalder | ||
|
||
Permission is hereby granted, free of charge, to any person or entity obtaining a copy of this software and associated documentation files (the "Software"), to use the software in any capacity, including commercial and for-profit use. Permission is also granted to alter, modify, or extend the Software for your own use, or commission a third-party to perform modifications for you. | ||
|
||
Permission is NOT granted to create derivative works, sublicense, and/or sell copies of the Software. This is not FOSS software. | ||
|
||
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,90 @@ | ||
# Commerce Friendly Order Numbers plugin for Craft CMS | ||
|
||
Use nice, client friendly consecutive order numbers with Craft Commerce | ||
|
||
## Installation | ||
|
||
Installation is slightly more involved than some plugins as I haven't automated everything (yet?). | ||
|
||
First, create a new field - we use `Friendly Order Number` (the handle *must* be `friendlyOrderNumber`) - but you can actually call the field whatever you like. | ||
|
||
The best field type to use is a Read Only 'Incognito' field (see https://github.com/mmikkel/IncognitoField-Craft) ...however if you want to avoid another plugin, just use a `Plain Text` field. | ||
|
||
![alt text](screenshots/FriendlyOrderNumber-Field-Settings.png "Field Settings - note the handle!") | ||
|
||
Add this new field to your Order Fields in Commerce settings: | ||
|
||
![alt text](screenshots/FriendlyOrderNumber-Order-Fields.png "Order Fields") | ||
|
||
Then, to actually install this plugin, follow these steps: | ||
|
||
1. Downloaded the latest release | ||
2. Unzip and copy the plugin folder `commercefriendlyordernumbers` to your `craft/plugins` folder | ||
3. Install plugin in the Craft Control Panel under Settings > Plugins | ||
4. N.B. The plugin folder should be named `commercefriendlyordernumbers` for Craft to see it. | ||
|
||
## Setting The Starting Order Number | ||
|
||
By default the plugin will start with order number #1. If you want to change this, simply change the value in the database to *one less than* whatever you'd like the order numbers to start from - so if you want to start from 25001, then set the value to 25000, like so: | ||
|
||
![alt text](screenshots/FriendlyOrderNumber-SetStartingNumber.png "Order Start Number") | ||
|
||
|
||
## Using The Friendly Order Number In Templates & Emails | ||
|
||
Generally, you can just refer to your new order number like any other field: | ||
`{{ order.friendlyOrderNumber }}` | ||
|
||
You can of course select orders by this field, e.g. using a url segment: | ||
|
||
`{% set order = craft.commerce.orders.friendlyOrderNumber(craft.request.getSegment(2)).customer(craft.commerce.customer).first() %}` | ||
|
||
**ONE BIG CAVEAT** - (apparently fixed in Commerce 1.2 but as yet untested by me) | ||
|
||
If you want to use the order number in your order receipt email, it won't yet have been saved to the order's database record. In this one case you must refer to it so: | ||
|
||
`{% set friendlyOrderNumber = order.content.friendlyOrderNumber ?? 'NONE' %}` | ||
|
||
(note the important `.content` in there!) | ||
|
||
There is also a template variable helper to get the latest used order number should you want to boast about how many orders you're putting through or something: | ||
|
||
`{{ craft.commerceFriendlyOrderNumbers.latestOrderNumber }}` | ||
|
||
## Using The Friendly Order Number In The Control Panel | ||
|
||
You can add the order number as a column in your order views, and then search by the number, using the standard craft approach (cog icon in Orders view): | ||
|
||
![alt text](screenshots/FriendlyOrderNumber-AddOrderNumberColumn.png "Order Start Number") | ||
|
||
To take it a step further you can replace Commerce order number on the order details page with your nicer number. You'll need to use the wonderful CPJS plugin (https://github.com/lindseydiloreto/craft-cpjs) - add this JS: | ||
|
||
if($("body").hasClass('commerceordersedit')){ | ||
// Change the Page Title and Order Number at the top to the Friendly Order Number | ||
var $pagetitle = $('#page-title'); | ||
var FriendlyOrderNumber = $("#fields-FriendlyOrderNumber").val(); | ||
$pagetitle.html("<h1>Order #" + FriendlyOrderNumber + "</h1>"); | ||
document.title = "Order #" + FriendlyOrderNumber; | ||
} | ||
|
||
And wa la, nice order numbers pretty much everywhere (and note you still have the Commerce number there too, of course): | ||
|
||
![alt text](screenshots/FriendlyOrderNumber-OrderEditView.png "Order Start Number") | ||
|
||
## Commerce Friendly Order Numbers Changelog | ||
|
||
Commerce Friendly Order Numbers has been tested with Craft 2.6+ and Commerce 1.1+, and is in daily use on working, live stores. | ||
|
||
### 0.0.1 -- 2016.09.06 | ||
|
||
* Initial release | ||
|
||
Brought to you by [Jeremy Daalder](https://github.com/bossanova808) | ||
|
||
## Issues? | ||
|
||
Please use github issues or find me on the Craft slack, I mostly hang out in the #commerce channel | ||
|
||
## Icon | ||
|
||
Public Doamin, from the Noun Project |
133 changes: 133 additions & 0 deletions
133
commercefriendlyordernumbers/CommerceFriendlyOrderNumbersPlugin.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,133 @@ | ||
<?php | ||
/** | ||
* CommerceFriendlyOrderNumbers plugin for Craft CMS | ||
* | ||
* Allows you to use friendly, consecutive order numbers instead of the default Commerce order numbers. | ||
* | ||
* @author Jeremy Daalder | ||
* @copyright Copyright (c) 2016 Jeremy Daalder | ||
* @link https://github.com/bossanova808 | ||
* @package CommerceFriendlyOrderNumbers | ||
* @since 0.0.1 | ||
*/ | ||
|
||
namespace Craft; | ||
|
||
class CommerceFriendlyOrderNumbersPlugin extends BasePlugin | ||
{ | ||
/** | ||
* @return mixed | ||
*/ | ||
public function init() | ||
{ | ||
craft()->on('commerce_orders.onBeforeOrderComplete', | ||
[ | ||
craft()->commerceFriendlyOrderNumbers, | ||
"onBeforeOrderCompleteHandler" | ||
] | ||
); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getName() | ||
{ | ||
return Craft::t('Commerce Friendly Order Numbers'); | ||
} | ||
|
||
/** | ||
* @return mixed | ||
*/ | ||
public function getDescription() | ||
{ | ||
return Craft::t('Allows you to use friendly, consecutive order numbers instead of the default Commerce order numbers.'); | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDocumentationUrl() | ||
{ | ||
return 'https://github.com/bossanova808/commercefriendlyordernumbers/blob/master/README.md'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getReleaseFeedUrl() | ||
{ | ||
return 'https://raw.githubusercontent.com/bossanova808/commercefriendlyordernumbers/master/releases.json'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getVersion() | ||
{ | ||
return '0.0.1'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getSchemaVersion() | ||
{ | ||
return '0.0.1'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDeveloper() | ||
{ | ||
return 'Jeremy Daalder'; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getDeveloperUrl() | ||
{ | ||
return 'https://github.com/bossanova808'; | ||
} | ||
|
||
/** | ||
* @return bool | ||
*/ | ||
public function hasCpSection() | ||
{ | ||
return false; | ||
} | ||
|
||
/** | ||
*/ | ||
public function onBeforeInstall() | ||
{ | ||
//Create the world's simplest table - holds one number | ||
craft()->db->createCommand()->createTable("commercefriendlyordernumbers_ordernumber",["id"=>"pk","orderNumber"=>"int"]); | ||
craft()->db->createCommand()->insert("commercefriendlyordernumbers_ordernumber",["id"=>"1","orderNumber"=>"0"]); | ||
} | ||
|
||
/** | ||
*/ | ||
public function onAfterInstall() | ||
{ | ||
} | ||
|
||
/** | ||
*/ | ||
public function onBeforeUninstall() | ||
{ | ||
//Tidy up after ourselves | ||
craft()->db->createCommand()->dropTable("commercefriendlyordernumbers_ordernumber"); | ||
} | ||
|
||
/** | ||
*/ | ||
public function onAfterUninstall() | ||
{ | ||
} | ||
|
||
|
||
} |
11 changes: 11 additions & 0 deletions
11
commercefriendlyordernumbers/resources/css/CommerceFriendlyOrderNumbers_Style.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* CommerceFriendlyOrderNumbers plugin for Craft CMS | ||
* | ||
* CommerceFriendlyOrderNumbers CSS | ||
* | ||
* @author Jeremy Daalder | ||
* @copyright Copyright (c) 2016 Jeremy Daalder | ||
* @link https://github.com/bossanova808 | ||
* @package CommerceFriendlyOrderNumbers | ||
* @since 0.0.1 | ||
*/ |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions
11
commercefriendlyordernumbers/resources/js/CommerceFriendlyOrderNumbers_Script.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
/** | ||
* CommerceFriendlyOrderNumbers plugin for Craft CMS | ||
* | ||
* CommerceFriendlyOrderNumbers JS | ||
* | ||
* @author Jeremy Daalder | ||
* @copyright Copyright (c) 2016 Jeremy Daalder | ||
* @link https://github.com/bossanova808 | ||
* @package CommerceFriendlyOrderNumbers | ||
* @since 0.0.1 | ||
*/ |
57 changes: 57 additions & 0 deletions
57
commercefriendlyordernumbers/services/CommerceFriendlyOrderNumbersService.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<?php | ||
/** | ||
* CommerceFriendlyOrderNumbers plugin for Craft CMS | ||
* | ||
* CommerceFriendlyOrderNumbers Service | ||
* | ||
* @author Jeremy Daalder | ||
* @copyright Copyright (c) 2016 Jeremy Daalder | ||
* @link https://github.com/bossanova808 | ||
* @package CommerceFriendlyOrderNumbers | ||
* @since 0.0.1 | ||
*/ | ||
|
||
namespace Craft; | ||
|
||
class CommerceFriendlyOrderNumbersService extends BaseApplicationComponent | ||
{ | ||
|
||
/** | ||
* Supply the latest unused firendly order number because Commerce order numbers suck for clients | ||
* | ||
* @param $increment=true - whether to return the next (new) number, or the current latest (used) order number. Defaults to next. | ||
* @return integer | ||
*/ | ||
public function getNextOrderNumber($increment=true) | ||
{ | ||
if($increment){ | ||
craft()->db->createCommand()->setText('update craft_commercefriendlyordernumbers_ordernumber set orderNumber = orderNumber + 1 where id=1')->execute(); | ||
} | ||
$result = craft()->db->createCommand()->setText('select orderNumber from craft_commercefriendlyordernumbers_ordernumber where id=1')->queryAll(); | ||
$result = $result[0]['orderNumber']; | ||
return $result; | ||
|
||
} | ||
|
||
/** | ||
* | ||
* Sets the Friendly Order Number to the order just as it is saved | ||
* @param $event | ||
* @throws Exception | ||
* @throws \Exception | ||
* @param $event | ||
*/ | ||
public function onBeforeOrderCompleteHandler($event){ | ||
|
||
$order = $event->params['order']; | ||
|
||
//SET THE IS ORDER NUMBER | ||
$orderNumber = $this->getNextOrderNumber(); | ||
$order->setContentFromPost(array( | ||
'friendlyOrderNumber' => $orderNumber, | ||
)); | ||
craft()->commerce_orders->saveOrder($order); | ||
|
||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<?php | ||
/** | ||
* CommerceFriendlyOrderNumbers plugin for Craft CMS | ||
* | ||
* CommerceFriendlyOrderNumbers Translation | ||
* | ||
* @author Jeremy Daalder | ||
* @copyright Copyright (c) 2016 Jeremy Daalder | ||
* @link https://github.com/bossanova808 | ||
* @package CommerceFriendlyOrderNumbers | ||
* @since 0.0.1 | ||
*/ | ||
|
||
return array( | ||
'Translate me' => 'To this', | ||
); |
25 changes: 25 additions & 0 deletions
25
commercefriendlyordernumbers/variables/CommerceFriendlyOrderNumbersVariable.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
/** | ||
* CommerceFriendlyOrderNumbers plugin for Craft CMS | ||
* | ||
* CommerceFriendlyOrderNumbers Variable | ||
* | ||
* @author Jeremy Daalder | ||
* @copyright Copyright (c) 2016 Jeremy Daalder | ||
* @link https://github.com/bossanova808 | ||
* @package CommerceFriendlyOrderNumbers | ||
* @since 0.0.1 | ||
*/ | ||
|
||
namespace Craft; | ||
|
||
class CommerceFriendlyOrderNumbersVariable | ||
{ | ||
/** Returns the latest used order number | ||
*/ | ||
public function latestOrderNumber() | ||
{ | ||
return craft()->commercefriendlyordernumbers->getNextOrderNumber(false); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
[ | ||
{ | ||
"version": "0.0.1", | ||
"downloadUrl": "https://github.com/bossanova808/CommerceFriendlyOrderNumbers/archive/0.0.1.zip", | ||
"date": "2016-09-23T05:41:01.158Z", | ||
"notes": [ | ||
"[Added] Initial release" | ||
] | ||
} | ||
] |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.