-
Notifications
You must be signed in to change notification settings - Fork 1
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
Showing
9 changed files
with
230 additions
and
16 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
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
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
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
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
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,40 @@ | ||
<?php | ||
/** | ||
* Purchase Patterns | ||
* | ||
* @link https://ethercreative.co.uk | ||
* @copyright Copyright (c) 2019 Ether Creative | ||
*/ | ||
|
||
namespace ether\purchasePatterns\elements\db; | ||
|
||
use craft\commerce\elements\db\ProductQuery; | ||
|
||
/** | ||
* Class ProductQueryExtended | ||
* | ||
* @author Ether Creative | ||
* @package ether\purchasePatterns\elements\db | ||
*/ | ||
class ProductQueryExtended extends ProductQuery | ||
{ | ||
|
||
protected function beforePrepare (): bool | ||
{ | ||
$this->innerJoin( | ||
'{{%purchase_counts}}', | ||
'[[commerce_products.id]] = [[purchase_counts.product_id]]' | ||
); | ||
|
||
$select = [ | ||
'[[purchase_counts.order_count]] AS orderCount', | ||
'[[purchase_counts.qty_count]] AS qtyCount', | ||
]; | ||
|
||
$this->query->select($select); | ||
$this->subQuery->select($select); | ||
|
||
return parent::beforePrepare(); | ||
} | ||
|
||
} |
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,56 @@ | ||
<?php | ||
/** | ||
* Purchase Patterns | ||
* | ||
* @link https://ethercreative.co.uk | ||
* @copyright Copyright (c) 2019 Ether Creative | ||
*/ | ||
|
||
namespace ether\purchasePatterns\jobs; | ||
|
||
use Craft; | ||
use craft\commerce\elements\Order; | ||
use craft\commerce\elements\Variant; | ||
use craft\queue\BaseJob; | ||
use craft\queue\QueueInterface; | ||
use ether\purchasePatterns\PurchasePatterns; | ||
use yii\base\InvalidConfigException; | ||
use yii\queue\Queue; | ||
|
||
/** | ||
* Class PopulateDataJob | ||
* | ||
* @author Ether Creative | ||
* @package ether\purchasePatterns\jobs | ||
*/ | ||
class PopulateDataJob extends BaseJob | ||
{ | ||
|
||
/** | ||
* @param Queue|QueueInterface $queue The queue the job belongs to | ||
* | ||
* @throws InvalidConfigException | ||
*/ | ||
public function execute ($queue) | ||
{ | ||
$completeOrders = Order::find()->isCompleted(true); | ||
$total = $completeOrders->count(); | ||
$service = PurchasePatterns::getInstance()->getService(); | ||
$loop = 0; | ||
|
||
// TODO: Clear tables if we allow users to run this later, after install | ||
|
||
/** @var Order $order */ | ||
foreach ($completeOrders->each() as $order) | ||
{ | ||
$this->setProgress($queue, $loop++ / $total); | ||
$service->tallyProducts($order); | ||
} | ||
} | ||
|
||
protected function defaultDescription () | ||
{ | ||
return Craft::t('purchase-patterns', 'Collating purchase pattern data'); | ||
} | ||
|
||
} |
Oops, something went wrong.