Skip to content
This repository has been archived by the owner on Apr 10, 2023. It is now read-only.

Commit

Permalink
1.1.0: Added new cache generators, changed cache iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
FlusherDock1 committed Feb 6, 2022
1 parent 8a060ce commit dc31a6b
Show file tree
Hide file tree
Showing 36 changed files with 1,913 additions and 1,692 deletions.
4 changes: 4 additions & 0 deletions Plugin.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,10 @@ public function register()
$this->registerConsoleCommand('shopahelper:cache.products', 'BizMark\Shopahelper\Console\Cache\GenerateProductsCache');
$this->registerConsoleCommand('shopahelper:cache.offers', 'BizMark\Shopahelper\Console\Cache\GenerateOffersCache');
$this->registerConsoleCommand('shopahelper:cache.brands', 'BizMark\Shopahelper\Console\Cache\GenerateBrandsCache');
$this->registerConsoleCommand('shopahelper:cache.measure', 'BizMark\ShopaHelper\Console\Cache\GenerateMeasureCache');
$this->registerConsoleCommand('shopahelper:cache.properties', 'BizMark\ShopaHelper\Console\Cache\GeneratePropertyCache');
$this->registerConsoleCommand('shopahelper:cache.propertysets', 'BizMark\ShopaHelper\Console\Cache\GeneratePropertySetCache');
$this->registerConsoleCommand('shopahelper:cache.propertyvalues', 'BizMark\ShopaHelper\Console\Cache\GeneratePropertyValueCache');

// Linkers
//// Brands
Expand Down
102 changes: 51 additions & 51 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,51 +1,51 @@
# Shopahelper plugin for Shopaholic

Shopahelper is a basic bulk tool that helps you to manage your catalog.

### Caching:
- `shopahelper:cache.all {chunk}` - Cache all Products, Brands, Categories, Offers by chunks with N items.
- `shopahelper:cache.products {chunk}` - Cache Products by chunks with N products.
- `shopahelper:cache.brands {chunk}` - Cache Brands by chunks with N brands.
- `shopahelper:cache.categories {chunk}` - Cache Categories by chunks with N categories.
- `shopahelper:cache.offers {chunk}` - Cache Offers by chunks with N offers.

### Generators
- `shopahelper:generate.offers` - Generating offers for each product that doesn't have it.

### Linkers

- `{products}` - In that variable you can pass a single ID or Multiple ID's separated by commas. Example: `shopahelper:link.brand-to-products 1 13,14,15` - Link Brand with id 1 to Products with id 13,14 and 15.


- Brands
- `shopahelper:link.brand-to-products {brand_id} {products}` - Link Brand by id to products by id's separated by comma.
- `shopahelper:link.brand-to-products-by-category {brand_id} {category_id}` - Link Brand by ID to products inside Category by ID
- Category
- `shopahelper:link.category-to-products {category_id} {products}` - Link Category by ID to Products by ID's separated by comma
- `shopahelper:link.category-to-products-by-category {old_category_id} {new_category_id}` - Link main Category ID to Products by their main Category ID;
- Additional Category
- `shopahelper:link.add-categories-to-products {category_id} {products}` - Link Additional Category by ID to Products by ID's separated by comma
- `shopahelper:link.add-category-to-products-by-add-category {target_category_id} {current_category_id}` - Link Additional Category by ID to Products that has additional category by ID
- `shopahelper:link.add-category-to-products-by-category {target_category_id} {current_category_id}` - Link Additional Category by ID to Products that has main Category by ID

### Detachers

- `{products}` - In that variable you can pass a single ID or Multiple ID's separated by commas.

- `shopahelper:detach.add-category-from-products {category} {products}` - Detaches Additional Category from Products by ID's separated by comma

### Prices

- `{products}` - In that variable you can pass a single ID or Multiple ID's separated by commas. Example: `shopahelper:price.upscale-by-percentage 10 13,14,15` - Upscale offers price by 10% in Products with id's 13,14,15
- `{category_tree}` - Boolean variable that accepts `true` or `false` strings. If passed `true` - proceeds action to all subcategories of target category.


- Upscale
- `shopahelper:price.upscale-by-percentage {percentage} {products}` - Upscale price by N percentage to Offers of Products by ID's separated by comma
- `shopahelper:price.upscale-by-percentage-by-brand {percentage} {brand_id}` - Upscale price by N percentage to Offers of Products of Brand by ID
- `shopahelper:price.upscale-by-percentage-by-category {percentage} {category_id} {category_tree}` - Upscale price by N percentage to Offers of Products of Category by ID.
- `shopahelper:price.upscale-by-percentage-custom` - Upscale price by N percentage to Offers of Products by ID's separated by comma with custom condition that you can specify in code.
- Downscale
- `shopahelper:price.downscale-by-percentage` - Downscale price by N percentage to Offers of Products by ID's separated by comma.
- `shopahelper:price.downscale-by-percentage-by-brand` - Downscale price by N percentage to Offers of Products of Brand by ID
- `shopahelper:price.downscale-by-percentage-by-category` - Downscale price by N percentage to Offers of Products of Category by ID.
# Shopahelper plugin for Shopaholic

Shopahelper is a basic bulk tool that helps you to manage your catalog.

### Caching:
- `shopahelper:cache.all {chunk}` - Cache all Products, Brands, Categories, Offers by chunks with N items.
- `shopahelper:cache.products {chunk}` - Cache Products by chunks with N products.
- `shopahelper:cache.brands {chunk}` - Cache Brands by chunks with N brands.
- `shopahelper:cache.categories {chunk}` - Cache Categories by chunks with N categories.
- `shopahelper:cache.offers {chunk}` - Cache Offers by chunks with N offers.

### Generators
- `shopahelper:generate.offers` - Generating offers for each product that doesn't have it.

### Linkers

- `{products}` - In that variable you can pass a single ID or Multiple ID's separated by commas. Example: `shopahelper:link.brand-to-products 1 13,14,15` - Link Brand with id 1 to Products with id 13,14 and 15.


- Brands
- `shopahelper:link.brand-to-products {brand_id} {products}` - Link Brand by id to products by id's separated by comma.
- `shopahelper:link.brand-to-products-by-category {brand_id} {category_id}` - Link Brand by ID to products inside Category by ID
- Category
- `shopahelper:link.category-to-products {category_id} {products}` - Link Category by ID to Products by ID's separated by comma
- `shopahelper:link.category-to-products-by-category {old_category_id} {new_category_id}` - Link main Category ID to Products by their main Category ID;
- Additional Category
- `shopahelper:link.add-categories-to-products {category_id} {products}` - Link Additional Category by ID to Products by ID's separated by comma
- `shopahelper:link.add-category-to-products-by-add-category {target_category_id} {current_category_id}` - Link Additional Category by ID to Products that has additional category by ID
- `shopahelper:link.add-category-to-products-by-category {target_category_id} {current_category_id}` - Link Additional Category by ID to Products that has main Category by ID

### Detachers

- `{products}` - In that variable you can pass a single ID or Multiple ID's separated by commas.

- `shopahelper:detach.add-category-from-products {category} {products}` - Detaches Additional Category from Products by ID's separated by comma

### Prices

- `{products}` - In that variable you can pass a single ID or Multiple ID's separated by commas. Example: `shopahelper:price.upscale-by-percentage 10 13,14,15` - Upscale offers price by 10% in Products with id's 13,14,15
- `{category_tree}` - Boolean variable that accepts `true` or `false` strings. If passed `true` - proceeds action to all subcategories of target category.


- Upscale
- `shopahelper:price.upscale-by-percentage {percentage} {products}` - Upscale price by N percentage to Offers of Products by ID's separated by comma
- `shopahelper:price.upscale-by-percentage-by-brand {percentage} {brand_id}` - Upscale price by N percentage to Offers of Products of Brand by ID
- `shopahelper:price.upscale-by-percentage-by-category {percentage} {category_id} {category_tree}` - Upscale price by N percentage to Offers of Products of Category by ID.
- `shopahelper:price.upscale-by-percentage-custom` - Upscale price by N percentage to Offers of Products by ID's separated by comma with custom condition that you can specify in code.
- Downscale
- `shopahelper:price.downscale-by-percentage` - Downscale price by N percentage to Offers of Products by ID's separated by comma.
- `shopahelper:price.downscale-by-percentage-by-brand` - Downscale price by N percentage to Offers of Products of Brand by ID
- `shopahelper:price.downscale-by-percentage-by-category` - Downscale price by N percentage to Offers of Products of Category by ID.
16 changes: 8 additions & 8 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "bizmark/shopahelper-plugin",
"type": "october-plugin",
"description": "The almighty helper in bulk actions for Shopaholic",
"require": {
"composer/installers": "~1.0"
}
}
{
"name": "bizmark/shopahelpershopaholic-plugin",
"type": "october-plugin",
"description": "The almighty helper in bulk actions for Shopaholic",
"require": {
"composer/installers": "~1.0"
}
}
40 changes: 27 additions & 13 deletions console/cache/CacheHelper.php
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
<?php namespace BizMark\Shopahelper\Console\Cache;

use Lovata\Shopaholic\Models\Brand;
use Lovata\Shopaholic\Models\Category;
use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Models\Product;

use Lovata\Shopaholic\Classes\Item\BrandItem;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
use Lovata\Shopaholic\Classes\Item\OfferItem;
use Lovata\Shopaholic\Classes\Item\ProductItem;

trait CacheHelper
{
/**
* Processing cache of given model and ElementItem
*
* @param string $sName
* @param string $obModel
* @param string $obModelItem
* @param string|Product|Category|Brand|Offer $obModel
* @param string|ProductItem|CategoryItem|BrandItem|OfferItem $obModelItem
*/
function generateCache($sName, $obModel, $obModelItem)
{
$this->output->writeln('Generating ' . $sName . ' cache.');
$this->info('Generating '.$sName.' cache.');
$obBar = $this->output->createProgressBar($obModel::active()->count());

foreach ($obModel::active()->orderBy('id')->cursor() as $obRecord) {
$obModelItem::make($obRecord->id);
$obBar->advance();
unset($obRecord);
}

$iChunkCount = $obModel::active()->count();
$iChunkCount = $iChunkCount / $this->argument('chunks');
$iChunkCount = round($iChunkCount);
$obBar->finish();
$this->getOutput()->newLine(2);

$obModel::active()->chunk($iChunkCount, function($records) use ($obModelItem, $sName) {
foreach ($records as $record) {
$obModelItem::make($record->id);
$this->output->writeln($sName . ' #' . $record->id . ' generated cache.');
}
});
unset($obBar);
unset($sName);
unset($obModel);
unset($obModelItem);
}
}
}
104 changes: 51 additions & 53 deletions console/cache/GenerateBrandsCache.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,51 @@
<?php namespace BizMark\Shopahelper\Console\Cache;

use Illuminate\Console\Command;

use Lovata\Shopaholic\Models\Brand;
use Lovata\Shopaholic\Classes\Item\BrandItem;

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class GenerateBrandsCache extends Command
{
use CacheHelper;

/**
* @var string The console command name.
*/
protected $name = 'shopahelper:cache.brands';

/**
* @var string The console command description.
*/
protected $description = 'Generate cache for brands';

/**
* Execute the console command.
* @return void
*/
public function handle()
{
$this->generateCache('Brand', Brand::class, BrandItem::class);
}

/**
* Get the console command arguments.
* @return array
*/
protected function getArguments()
{
return [
['chunks', InputArgument::REQUIRED, 'How many chunks of each collection to iterate. (2, 3, 4 and etc.)'],
];
}

/**
* Get the console command options.
* @return array
*/
protected function getOptions()
{
return [];
}
}
<?php namespace BizMark\Shopahelper\Console\Cache;

use Illuminate\Console\Command;

use Lovata\Shopaholic\Models\Brand;
use Lovata\Shopaholic\Classes\Item\BrandItem;

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;

class GenerateBrandsCache extends Command
{
use CacheHelper;

/**
* @var string The console command name.
*/
protected $name = 'shopahelper:cache.brands';

/**
* @var string The console command description.
*/
protected $description = 'Generate cache for brands';

/**
* Execute the console command.
* @return void
*/
public function handle()
{
$this->generateCache('Brand', Brand::class, BrandItem::class);
}

/**
* Get the console command arguments.
* @return array
*/
protected function getArguments()
{
return [];
}

/**
* Get the console command options.
* @return array
*/
protected function getOptions()
{
return [];
}
}
16 changes: 12 additions & 4 deletions console/cache/GenerateCache.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,18 @@
use Lovata\Shopaholic\Models\Offer;
use Lovata\Shopaholic\Models\Product;
use Lovata\Shopaholic\Models\Category;
use Lovata\PropertiesShopaholic\Models\Property;
use Lovata\PropertiesShopaholic\Models\PropertySet;
use Lovata\PropertiesShopaholic\Models\PropertyValue;

use Lovata\Shopaholic\Classes\Item\BrandItem;
use Lovata\Shopaholic\Classes\Item\OfferItem;
use Lovata\Shopaholic\Classes\Item\ProductItem;
use Lovata\Shopaholic\Classes\Item\CategoryItem;
use Lovata\Shopaholic\Classes\Item\MeasureItem;
use Lovata\PropertiesShopaholic\Classes\Item\PropertyItem;
use Lovata\PropertiesShopaholic\Classes\Item\PropertySetItem;
use Lovata\PropertiesShopaholic\Classes\Item\PropertyValueItem;

use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Input\InputArgument;
Expand All @@ -35,11 +42,14 @@ class GenerateCache extends Command
*/
public function handle()
{
$this->output->writeln('Starting process of caching Categories, Products, Offers, Brands');
$this->generateCache('Category', Category::class, CategoryItem::class);
$this->generateCache('Product', Product::class, ProductItem::class);
$this->generateCache('Offer', Offer::class, OfferItem::class);
$this->generateCache('Brand', Brand::class, BrandItem::class);
$this->generateCache('Measure', Measure::class, MeasureItem::class);
$this->generateCache('Property', Property::class, PropertyItem::class);
$this->generateCache('PropertySet', PropertySet::class, PropertySetItem::class);
$this->generateCache('PropertyValue', PropertyValue::class, PropertyValueItem::class);
}

/**
Expand All @@ -48,9 +58,7 @@ public function handle()
*/
protected function getArguments()
{
return [
['chunks', InputArgument::REQUIRED, 'How many chunks of each collection to iterate. (2, 3, 4 and etc.)'],
];
return [];
}

/**
Expand Down
Loading

0 comments on commit dc31a6b

Please sign in to comment.