Skip to content

Commit

Permalink
Merge branch 'master' into 1027-add_parameters_to_scenario_email
Browse files Browse the repository at this point in the history
* master: (60 commits)
  Add search/filter to product listing
  Unifying file/filename usages to stay consistent within system
  CRM is now capable of sending email via Mailer module serving as adapter
  Fixing missing sold products count if no product was sold yet
  Election crowdfunding added to main projects list
  Automatically added payment methods and subscription types to crowdfunding sales funnel
  Allow payment listings for sales funnel
  Removed redundant file
  Crowdfunding elections 2020 magazine
  add and use content meta repository add and get methods
  refactor subscription notifications 7/14 days email methods
  Support for content_access criterion in scenario builder condition node, improved UI in Scenario builder
  Fixing sniffer issue
  Adding command to charge single CID with custom amount and description
  Adding recurrent_payment parameter to subscription notification email
  Unused imports removed
  CHANGELOG updated
  add content meta table and repository + use in content updated handler
  Test for trigger stats added
  Fix incrementing of triggers and elements
  ...

# Conflicts:
#	app/config/config.internal.neon
#	app/modules/DenniknModule/events/CrowdfundingPaymentEmailNotificationHandler.php
#	app/modules/DenniknModule/events/ProformaInvoiceCreatedHandler.php
#	app/modules/DenniknModule/events/SendWelcomeEmailHandler.php
#	app/modules/DenniknModule/events/TBRecurrentPaymentFailHandler.php
#	app/modules/InternalModule/InternalModule.php
#	app/modules/InternalModule/events/NewSubscriptionHandler.php
#	app/modules/InternalModule/events/RecurrentPaymentRenewHandler.php
#	app/modules/InternalModule/events/SendNotificationAboutChangePasswordHandler.php
#	app/modules/InternalModule/events/SuspiciousEventHandler.php
#	app/modules/InternalModule/events/UserChangePasswordRequestHandler.php
#	app/modules/InternalModule/hermes/NewSubscriptionDelayedHandler.php
#	app/modules/MailerModule/forms/EmailSettingsFormFactory.php
#	extensions/users-module/src/events/NotificationEvent.php
  • Loading branch information
miroc committed Jan 17, 2020
2 parents 219664e + ef1587d commit d4727ca
Show file tree
Hide file tree
Showing 10 changed files with 114 additions and 28 deletions.
2 changes: 2 additions & 0 deletions src/commands/CalculateAveragesCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,7 @@ protected function execute(InputInterface $input, OutputInterface $output)
ON DUPLICATE KEY UPDATE `updated_at`=NOW(), `value`=VALUES(value);
SQL
);

return 0;
}
}
2 changes: 1 addition & 1 deletion src/events/PaymentStatusChangeHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ private function attachAttachments(ActiveRow $payment, ActiveRow $order, &$templ
$attachment = file_get_contents($attachmentName);
if ($attachment !== false) {
$attachments[] = [
'filename' => 'coupon.pdf',
'file' => 'coupon.pdf',
'content' => $attachment,
'mime_type' => 'application/pdf',
];
Expand Down
9 changes: 6 additions & 3 deletions src/lang/products.cs_CZ.neon
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ data:
sorting: Na první pozici
description: např. Tento produkt je super
ean: např. 8580000000000
image_url: napr. http://dennikn.sk/images/shop.jpg
image_url: např. http://dennikn.sk/images/shop.jpg
og_image_url: např. http://dennikn.sk/images/shop.jpg
images: např. http://dennikn.sk/images/shop.jpg
descriptions:
Expand Down Expand Up @@ -80,6 +80,9 @@ admin:
default:
header: Produkty
new: Vytvoriť produkt
admin_filter_form:
text:
placeholder: 'Název / Identifikátor / Veřejný popis / Cena'
new:
title: Nový produkt
back: Spať na zoznam
Expand Down Expand Up @@ -259,7 +262,7 @@ frontend:
pass_required: Položka Heslo je povinná.
account_exists: 'Účet se zadaným emailem již existuje, prosím přihlaste se pomocí hesla'
phone_number: 'Telefonní číslo (pomůže nám při doručování)'
phone_number_placeholder: 'Napr. 0908 123 456'
phone_number_placeholder: 'např. 0908 123 456'
phone_number_required: 'Položka Telefonní číslo je povinná.'
phone_number_min_length: 'Telefónne číslo musí mať aspon 6 znakov.'
want_invoice: Chci fakturu
Expand Down Expand Up @@ -338,7 +341,7 @@ config:
category: Obchod
shop_host:
name: URL obchodu
description: 'URL obchodu (v případě, že běží na vlastní doméně; napr. obchod.crm.press)'
description: 'URL obchodu (v případě, že běží na vlastní doméně; např. obchod.crm.press)'
shop_header_block:
name: Kód v hlavičce pro obchod
description: 'Libovolný kód (např. Google analytics nebo další), který se má vložit do hlavičky šablony obchodu'
Expand Down
4 changes: 4 additions & 0 deletions src/lang/products.en_US.neon
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ admin:
default:
header: Products
new: Create product
admin_filter_form:
text:
placeholder: 'Name / Identifier / Label / Price'

new:
title: New product
back: Back to the list
Expand Down
4 changes: 4 additions & 0 deletions src/lang/products.sk_SK.neon
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,10 @@ admin:
default:
header: Produkty
new: Vytvoriť produkt
admin_filter_form:
text:
placeholder: 'Názov / Identifikátor / Verejný popis / Cena'

new:
title: Nový produkt
back: Spať na zoznam
Expand Down
2 changes: 1 addition & 1 deletion src/models/Ebook/EbookProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
class EbookProvider
{
/** @var EbookProviderInterface[] */
private $providers;
private $providers = [];

public function register(EbookProviderInterface $ebookProvider)
{
Expand Down
27 changes: 25 additions & 2 deletions src/models/Repository/ProductsRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,32 @@ public function __construct(
$this->productShopCountsDistribution = $productShopCountsDistribution;
}

public function all()
public function all(string $search = null)
{
return $this->getTable()->order('-sorting DESC, name ASC');
$all = $this->getTable()->order('-sorting DESC, name ASC');

if (is_null($search) || empty(trim($search))) {
return $all;
}

$searchText = "%{$search}%";
$conditions = [
'name LIKE ?' => $searchText,
'code LIKE ?' => $searchText,
'user_label LIKE ?' => $searchText,
];

// check if searched text is number (replace comma with period; otherwise is_numeric won't work)
$searchNum = str_replace(',', '.', $search);
if (is_numeric($searchNum)) {
$searchFloat = floatval($searchNum);
$conditions = array_merge($conditions, [
'price = ?' => $searchFloat,
'catalog_price = ?' => $searchFloat,
]);
}

return $all->whereOr($conditions);
}

public function getByCode($code)
Expand Down
36 changes: 21 additions & 15 deletions src/models/ShopPaymentCompleteRedirectResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,34 @@ class ShopPaymentCompleteRedirectResolver implements PaymentCompleteRedirectReso
{
public function wantsToRedirect(?ActiveRow $payment, string $status): bool
{
if ($payment && $status === self::PAID) {
return !empty($payment->related('order')->fetch());
}
if ($status === self::ERROR) {
return !empty($payment->related('order')->fetch());
if ($payment) {
if ($status === self::PAID) {
return !empty($payment->related('order')->fetch());
}
if ($status === self::ERROR) {
return !empty($payment->related('order')->fetch());
}
}

return false;
}

public function redirectArgs(?ActiveRow $payment, string $status): array
{
if ($payment && $status === self::PAID) {
return [
':Products:Shop:Success',
['id' => $payment->variable_symbol],
];
}
if ($status === self::ERROR) {
return [
':Products:Shop:Error',
];
if ($payment) {
if ($status === self::PAID) {
return [
':Products:Shop:Success',
['id' => $payment->variable_symbol],
];
}
if ($status === self::ERROR) {
return [
':Products:Shop:Error',
];
}
}

throw new \Exception('unhandled status when requesting redirectArgs (did you check wantsToRedirect first?): ' . $status);
}
}
49 changes: 44 additions & 5 deletions src/presenters/ProductsAdminPresenter.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,21 @@

namespace Crm\ProductsModule\Presenters;

use Crm\AdminModule\Presenters\AdminPresenter;
use Crm\ApplicationModule\Components\Graphs\GoogleLineGraphGroupControlFactoryInterface;
use Crm\ApplicationModule\Components\VisualPaginator;
use Crm\ApplicationModule\Graphs\Criteria;
use Crm\ApplicationModule\Graphs\GraphDataItem;
use Crm\AdminModule\Presenters\AdminPresenter;
use Crm\PaymentsModule\Repository\PaymentItemsRepository;
use Crm\PaymentsModule\Repository\PaymentsRepository;
use Crm\ProductsModule\Forms\ProductsFormFactory;
use Crm\ProductsModule\PaymentItem\ProductPaymentItem;
use Crm\ProductsModule\Repository\ProductsRepository;
use Nette\Application\UI\Form;
use Nette\Database\Table\ActiveRow;
use Nette\Database\Table\IRow;
use Nette\Http\Request;
use Tomaj\Form\Renderer\BootstrapInlineRenderer;

class ProductsAdminPresenter extends AdminPresenter
{
Expand All @@ -39,11 +41,16 @@ public function __construct(
$this->paymentItemsRepository = $paymentItemsRepository;
}

public function renderDefault()
public function startup()
{
$products = $this->productsRepository->all();
parent::startup();
$this->text = isset($this->params['text']) ? $this->params['text'] : null;
}

$filteredCount = $this->template->filteredCount = $products->count('*');
public function renderDefault()
{
$products = $this->productsRepository->all($this->text);
$filteredCount = $products->count();

$vp = new VisualPaginator();
$this->addComponent($vp, 'products_vp');
Expand All @@ -53,6 +60,9 @@ public function renderDefault()

$this->template->vp = $vp;
$this->template->products = $products->limit($paginator->getLength(), $paginator->getOffset());

$this->template->allProductsCount = $this->productsRepository->all()->count();
$this->template->filteredProductsCount = $filteredCount;
}

public function renderShow($id)
Expand Down Expand Up @@ -92,7 +102,7 @@ private function getProductSalesCount(IRow $product)
return $this->paymentItemsRepository->getTable()
->where('product_id', $product->id)
->where('payment.status', PaymentsRepository::STATUS_PAID)
->fetchField('COUNT(`count`)');
->fetchField('COALESCE(SUM(`count`), 0)');
}

public function renderUserList(int $id, string $type, float $fromLevel, float $toLevel = null)
Expand Down Expand Up @@ -168,4 +178,33 @@ protected function createComponentSaleGraph(GoogleLineGraphGroupControlFactoryIn

return $control;
}

public function createComponentAdminFilterForm()
{
$form = new Form;
$form->setRenderer(new BootstrapInlineRenderer());
$form->addText('text', $this->translator->translate('system.filter'), 50)
->setAttribute('placeholder', $this->translator->translate('products.admin.products.default.admin_filter_form.text.placeholder'))
->setAttribute('autofocus');

$form->addSubmit('send', $this->translator->translate('system.filter'))
->getControlPrototype()
->setName('button')
->setHtml('<i class="fa fa-filter"></i> ' . $this->translator->translate('system.filter'));
$presenter = $this;
$form->addSubmit('cancel', $this->translator->translate('system.cancel_filter'))
->onClick[] = function () use ($presenter) {
$presenter->redirect('ProductsAdmin:Default', ['text' => '']);
};

$form->setDefaults((array)$this->params);

$form->onSuccess[] = [$this, 'adminFilterSubmited'];
return $form;
}

public function adminFilterSubmited(Form $form, array $values)
{
$this->redirect('Default', $values);
}
}
7 changes: 6 additions & 1 deletion src/templates/ProductsAdmin/default.latte
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,17 @@
<h1>
{_products.admin.products.default.header}
<small>
/ {_system.total} {$filteredCount}
/ {_system.total} {$allProductsCount}
{if $allProductsCount != $filteredProductsCount}
, {_system.filtered} {$filteredProductsCount}
{/if}
</small>
<a n:href="new" class="btn btn-success btn-lg pull-right"><i
class="fa fa-sliders-h"></i> {_products.admin.products.default.new}</a>
</h1>
<hr>
{control adminFilterForm}
<hr>
</div>

<div class="col-md-12">
Expand Down

0 comments on commit d4727ca

Please sign in to comment.