ver. 0.289: ShopCategory + ShopClient frontend migration to Domain + Views + Controllers
ShopCategory: 9 frontend methods in CategoryRepository, front\Views\ShopCategory (3 methods), deleted factory + view, updated 6 callers, +17 tests. ShopClient: 13 frontend methods in ClientRepository, front\Views\ShopClient (8 methods), front\Controllers\ShopClientController (15 methods + buildEmailBody helper), deleted factory + view + controls, updated 7 callers, +36 tests. Security fix: removed hardcoded password bypass 'Legia1916'. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -15,6 +15,26 @@ class CategoryRepository
|
||||
6 => 'alfabetycznie - Z - A',
|
||||
];
|
||||
|
||||
private const SORT_ORDER_SQL = [
|
||||
0 => 'q1.date_add ASC',
|
||||
1 => 'q1.date_add DESC',
|
||||
2 => 'q1.date_modify ASC',
|
||||
3 => 'q1.date_modify DESC',
|
||||
4 => 'q1.o ASC',
|
||||
5 => 'q1.name ASC',
|
||||
6 => 'q1.name DESC',
|
||||
];
|
||||
|
||||
private const PRODUCTS_PER_PAGE = 12;
|
||||
|
||||
private const LANGUAGE_FALLBACK_NAME_SQL = '(CASE '
|
||||
. 'WHEN copy_from IS NULL THEN name '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ('
|
||||
. 'SELECT name FROM pp_shop_products_langs '
|
||||
. 'WHERE lang_id = pspl.copy_from AND product_id = psp.id'
|
||||
. ') '
|
||||
. 'END) AS name';
|
||||
|
||||
public function __construct($db)
|
||||
{
|
||||
$this->db = $db;
|
||||
@@ -317,6 +337,330 @@ class CategoryRepository
|
||||
return (string)$title[0];
|
||||
}
|
||||
|
||||
// ===== Frontend methods =====
|
||||
|
||||
public function getCategorySort(int $categoryId): int
|
||||
{
|
||||
if ($categoryId <= 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "get_category_sort:$categoryId";
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($objectData) {
|
||||
return (int)unserialize($objectData);
|
||||
}
|
||||
|
||||
$sortType = (int)$this->db->get('pp_shop_categories', 'sort_type', ['id' => $categoryId]);
|
||||
$cacheHandler->set($cacheKey, $sortType);
|
||||
|
||||
return $sortType;
|
||||
}
|
||||
|
||||
public function categoryName(int $categoryId, string $langId): string
|
||||
{
|
||||
if ($categoryId <= 0 || $langId === '') {
|
||||
return '';
|
||||
}
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "category_name:{$langId}:{$categoryId}";
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($objectData) {
|
||||
return (string)unserialize($objectData);
|
||||
}
|
||||
|
||||
$name = $this->db->get('pp_shop_categories_langs', 'title', [
|
||||
'AND' => [
|
||||
'category_id' => $categoryId,
|
||||
'lang_id' => $langId,
|
||||
],
|
||||
]);
|
||||
|
||||
$cacheHandler->set($cacheKey, $name);
|
||||
|
||||
return (string)$name;
|
||||
}
|
||||
|
||||
public function categoryUrl(int $categoryId, string $langId): string
|
||||
{
|
||||
if ($categoryId <= 0) {
|
||||
return '#';
|
||||
}
|
||||
|
||||
$category = $this->frontCategoryDetails($categoryId, $langId);
|
||||
if (empty($category)) {
|
||||
return '#';
|
||||
}
|
||||
|
||||
$url = !empty($category['language']['seo_link'])
|
||||
? '/' . $category['language']['seo_link']
|
||||
: '/k-' . $category['id'] . '-' . \Shared\Helpers\Helpers::seo($category['language']['title'] ?? '');
|
||||
|
||||
$currentLang = \Shared\Helpers\Helpers::get_session('current-lang');
|
||||
$defaultLang = (new \Domain\Languages\LanguagesRepository($this->db))->defaultLanguage();
|
||||
|
||||
if ($currentLang != $defaultLang && $url !== '#') {
|
||||
$url = '/' . $currentLang . $url;
|
||||
}
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function frontCategoryDetails(int $categoryId, string $langId): array
|
||||
{
|
||||
if ($categoryId <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "front_category_details:{$categoryId}:{$langId}";
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($objectData) {
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
$category = $this->db->get('pp_shop_categories', '*', ['id' => $categoryId]);
|
||||
if (!is_array($category)) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$category['language'] = $this->db->get('pp_shop_categories_langs', '*', [
|
||||
'AND' => [
|
||||
'category_id' => $categoryId,
|
||||
'lang_id' => $langId,
|
||||
],
|
||||
]);
|
||||
|
||||
$cacheHandler->set($cacheKey, $category);
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function categoriesTree(string $langId, ?int $parentId = null): array
|
||||
{
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "categories_tree:{$langId}:{$parentId}";
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($objectData) {
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
$categories = [];
|
||||
$results = $this->db->select('pp_shop_categories', 'id', [
|
||||
'parent_id' => $parentId,
|
||||
'ORDER' => ['o' => 'ASC'],
|
||||
]);
|
||||
|
||||
if (is_array($results)) {
|
||||
foreach ($results as $row) {
|
||||
$category = $this->frontCategoryDetails((int)$row, $langId);
|
||||
$category['categories'] = $this->categoriesTree($langId, (int)$row);
|
||||
$categories[] = $category;
|
||||
}
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $categories);
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
public function blogCategoryProducts(int $categoryId, string $langId, int $limit): array
|
||||
{
|
||||
if ($categoryId <= 0 || $langId === '' || $limit <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "blog_category_products:{$categoryId}:{$langId}:{$limit}";
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($objectData) {
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
$rows = $this->db->query(
|
||||
'SELECT * FROM ('
|
||||
. 'SELECT '
|
||||
. 'psp.id, date_modify, date_add, o, '
|
||||
. self::LANGUAGE_FALLBACK_NAME_SQL . ' '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_categories AS pspc '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
|
||||
. 'INNER JOIN pp_shop_products_langs AS pspl ON pspl.product_id = pspc.product_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND category_id = :category_id AND lang_id = :lang_id'
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.name IS NOT NULL '
|
||||
. 'ORDER BY '
|
||||
. 'RAND() '
|
||||
. 'LIMIT ' . (int)$limit,
|
||||
[
|
||||
':category_id' => $categoryId,
|
||||
':lang_id' => $langId,
|
||||
]
|
||||
);
|
||||
|
||||
$output = [];
|
||||
if ($rows) {
|
||||
foreach ($rows->fetchAll() as $row) {
|
||||
$output[] = $row['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $output);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public function categoryProductsCount(int $categoryId, string $langId): int
|
||||
{
|
||||
if ($categoryId <= 0 || $langId === '') {
|
||||
return 0;
|
||||
}
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "category_products_count:{$categoryId}:{$langId}";
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($objectData) {
|
||||
return (int)unserialize($objectData);
|
||||
}
|
||||
|
||||
$rows = $this->db->query(
|
||||
'SELECT COUNT(0) FROM ('
|
||||
. 'SELECT '
|
||||
. 'psp.id, '
|
||||
. self::LANGUAGE_FALLBACK_NAME_SQL . ' '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_categories AS pspc '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
|
||||
. 'INNER JOIN pp_shop_products_langs AS pspl ON pspl.product_id = pspc.product_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND category_id = :category_id AND lang_id = :lang_id'
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.name IS NOT NULL',
|
||||
[
|
||||
':category_id' => $categoryId,
|
||||
':lang_id' => $langId,
|
||||
]
|
||||
);
|
||||
|
||||
$productsCount = 0;
|
||||
if ($rows) {
|
||||
$result = $rows->fetchAll();
|
||||
$productsCount = (int)($result[0][0] ?? 0);
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $productsCount);
|
||||
|
||||
return $productsCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, mixed>
|
||||
*/
|
||||
public function productsId(int $categoryId, int $sortType, string $langId, int $productsLimit, int $from): array
|
||||
{
|
||||
if ($categoryId <= 0 || $langId === '') {
|
||||
return [];
|
||||
}
|
||||
|
||||
$order = self::SORT_ORDER_SQL[$sortType] ?? self::SORT_ORDER_SQL[0];
|
||||
$today = date('Y-m-d');
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "products_id:{$categoryId}:{$sortType}:{$langId}:{$productsLimit}:{$from}";
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ($objectData) {
|
||||
return unserialize($objectData);
|
||||
}
|
||||
|
||||
$rows = $this->db->query(
|
||||
'SELECT * FROM ('
|
||||
. 'SELECT '
|
||||
. 'psp.id, date_modify, date_add, o, '
|
||||
. self::LANGUAGE_FALLBACK_NAME_SQL . ', '
|
||||
. '(CASE '
|
||||
. 'WHEN new_to_date >= :today THEN new_to_date '
|
||||
. 'WHEN new_to_date < :today2 THEN null '
|
||||
. 'END) AS new_to_date, '
|
||||
. '(CASE WHEN (quantity + (SELECT IFNULL(SUM(quantity),0) FROM pp_shop_products WHERE parent_id = psp.id)) > 0 THEN 1 ELSE 0 END) AS total_quantity '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_categories AS pspc '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
|
||||
. 'INNER JOIN pp_shop_products_langs AS pspl ON pspl.product_id = pspc.product_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND category_id = :category_id AND lang_id = :lang_id'
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.name IS NOT NULL '
|
||||
. 'ORDER BY '
|
||||
. $order . ' '
|
||||
. 'LIMIT ' . (int)$from . ',' . (int)$productsLimit,
|
||||
[
|
||||
':category_id' => $categoryId,
|
||||
':lang_id' => $langId,
|
||||
':today' => $today,
|
||||
':today2' => $today,
|
||||
]
|
||||
);
|
||||
|
||||
$output = [];
|
||||
if ($rows) {
|
||||
foreach ($rows->fetchAll() as $row) {
|
||||
$output[] = $row['id'];
|
||||
}
|
||||
}
|
||||
|
||||
$cacheHandler->set($cacheKey, $output);
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{products: array, ls: int}
|
||||
*/
|
||||
public function paginatedCategoryProducts(int $categoryId, int $sortType, string $langId, int $page): array
|
||||
{
|
||||
$count = $this->categoryProductsCount($categoryId, $langId);
|
||||
if ($count <= 0) {
|
||||
return ['products' => [], 'ls' => 0];
|
||||
}
|
||||
|
||||
$totalPages = (int)ceil($count / self::PRODUCTS_PER_PAGE);
|
||||
|
||||
if ($page < 1) {
|
||||
$page = 1;
|
||||
} elseif ($page > $totalPages) {
|
||||
$page = $totalPages;
|
||||
}
|
||||
|
||||
$from = self::PRODUCTS_PER_PAGE * ($page - 1);
|
||||
|
||||
return [
|
||||
'products' => $this->productsId($categoryId, $sortType, $langId, self::PRODUCTS_PER_PAGE, $from),
|
||||
'ls' => $totalPages,
|
||||
];
|
||||
}
|
||||
|
||||
private function maxOrder(): int
|
||||
{
|
||||
return (int)$this->db->max('pp_shop_categories', 'o');
|
||||
|
||||
@@ -234,6 +234,287 @@ class ClientRepository
|
||||
];
|
||||
}
|
||||
|
||||
// ===== Frontend methods =====
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function clientDetails(int $clientId): ?array
|
||||
{
|
||||
if ($clientId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->db->get('pp_shop_clients', '*', ['id' => $clientId]) ?: null;
|
||||
}
|
||||
|
||||
public function clientEmail(int $clientId): ?string
|
||||
{
|
||||
if ($clientId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$email = $this->db->get('pp_shop_clients', 'email', ['id' => $clientId]);
|
||||
|
||||
return $email ? (string)$email : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function clientAddresses(int $clientId): array
|
||||
{
|
||||
if ($clientId <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = $this->db->select('pp_shop_clients_addresses', '*', ['client_id' => $clientId]);
|
||||
|
||||
return is_array($rows) ? $rows : [];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<string, mixed>|null
|
||||
*/
|
||||
public function addressDetails(int $addressId): ?array
|
||||
{
|
||||
if ($addressId <= 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->db->get('pp_shop_clients_addresses', '*', ['id' => $addressId]) ?: null;
|
||||
}
|
||||
|
||||
public function addressDelete(int $addressId): bool
|
||||
{
|
||||
if ($addressId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return (bool)$this->db->delete('pp_shop_clients_addresses', ['id' => $addressId]);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array<string, string> $data Keys: name, surname, street, postal_code, city, phone
|
||||
*/
|
||||
public function addressSave(int $clientId, ?int $addressId, array $data): bool
|
||||
{
|
||||
if ($clientId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$row = [
|
||||
'name' => (string)($data['name'] ?? ''),
|
||||
'surname' => (string)($data['surname'] ?? ''),
|
||||
'street' => (string)($data['street'] ?? ''),
|
||||
'postal_code' => (string)($data['postal_code'] ?? ''),
|
||||
'city' => (string)($data['city'] ?? ''),
|
||||
'phone' => (string)($data['phone'] ?? ''),
|
||||
];
|
||||
|
||||
if (!$addressId || $addressId <= 0) {
|
||||
$row['client_id'] = $clientId;
|
||||
return (bool)$this->db->insert('pp_shop_clients_addresses', $row);
|
||||
}
|
||||
|
||||
return (bool)$this->db->update('pp_shop_clients_addresses', $row, [
|
||||
'AND' => [
|
||||
'client_id' => $clientId,
|
||||
'id' => $addressId,
|
||||
],
|
||||
]);
|
||||
}
|
||||
|
||||
public function markAddressAsCurrent(int $clientId, int $addressId): bool
|
||||
{
|
||||
if ($clientId <= 0 || $addressId <= 0) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->db->update('pp_shop_clients_addresses', ['current' => 0], ['client_id' => $clientId]);
|
||||
$this->db->update('pp_shop_clients_addresses', ['current' => 1], [
|
||||
'AND' => [
|
||||
'client_id' => $clientId,
|
||||
'id' => $addressId,
|
||||
],
|
||||
]);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array<int, array<string, mixed>>
|
||||
*/
|
||||
public function clientOrders(int $clientId): array
|
||||
{
|
||||
if ($clientId <= 0) {
|
||||
return [];
|
||||
}
|
||||
|
||||
$rows = $this->db->select('pp_shop_orders', 'id', [
|
||||
'client_id' => $clientId,
|
||||
'ORDER' => ['date_order' => 'DESC'],
|
||||
]);
|
||||
|
||||
$orders = [];
|
||||
if (is_array($rows)) {
|
||||
foreach ($rows as $row) {
|
||||
$orders[] = \front\factory\ShopOrder::order_details($row);
|
||||
}
|
||||
}
|
||||
|
||||
return $orders;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{status: string, client?: array, hash?: string, code?: string}
|
||||
*/
|
||||
public function authenticate(string $email, string $password): array
|
||||
{
|
||||
$email = trim($email);
|
||||
$password = trim($password);
|
||||
|
||||
if ($email === '' || $password === '') {
|
||||
return ['status' => 'error', 'code' => 'logowanie-nieudane'];
|
||||
}
|
||||
|
||||
$client = $this->db->get('pp_shop_clients', [
|
||||
'id', 'password', 'register_date', 'hash', 'status',
|
||||
], ['email' => $email]);
|
||||
|
||||
if (!$client) {
|
||||
return ['status' => 'error', 'code' => 'logowanie-nieudane'];
|
||||
}
|
||||
|
||||
if (!(int)$client['status']) {
|
||||
return ['status' => 'inactive', 'hash' => $client['hash']];
|
||||
}
|
||||
|
||||
if ($client['password'] !== md5($client['register_date'] . $password)) {
|
||||
return ['status' => 'error', 'code' => 'logowanie-blad-nieprawidlowe-haslo'];
|
||||
}
|
||||
|
||||
$fullClient = $this->clientDetails((int)$client['id']);
|
||||
|
||||
return ['status' => 'ok', 'client' => $fullClient];
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array{id: int, hash: string}|null Null when email already taken
|
||||
*/
|
||||
public function createClient(string $email, string $password, bool $agreementMarketing): ?array
|
||||
{
|
||||
$email = trim($email);
|
||||
if ($email === '' || $password === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
if ($this->db->count('pp_shop_clients', ['email' => $email])) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hash = md5(time() . $email);
|
||||
$registerDate = date('Y-m-d H:i:s');
|
||||
|
||||
$inserted = $this->db->insert('pp_shop_clients', [
|
||||
'email' => $email,
|
||||
'password' => md5($registerDate . $password),
|
||||
'hash' => $hash,
|
||||
'agremment_marketing' => $agreementMarketing ? 1 : 0,
|
||||
'register_date' => $registerDate,
|
||||
]);
|
||||
|
||||
if (!$inserted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return [
|
||||
'id' => (int)$this->db->id(),
|
||||
'hash' => $hash,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Confirms registration. Returns client email on success, null on failure.
|
||||
*/
|
||||
public function confirmRegistration(string $hash): ?string
|
||||
{
|
||||
$hash = trim($hash);
|
||||
if ($hash === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$id = $this->db->get('pp_shop_clients', 'id', [
|
||||
'AND' => ['hash' => $hash, 'status' => 0],
|
||||
]);
|
||||
|
||||
if (!$id) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->db->update('pp_shop_clients', ['status' => 1], ['id' => $id]);
|
||||
|
||||
$email = $this->db->get('pp_shop_clients', 'email', ['id' => $id]);
|
||||
|
||||
return $email ? (string)$email : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates new password. Returns [email, password] on success, null on failure.
|
||||
*
|
||||
* @return array{email: string, password: string}|null
|
||||
*/
|
||||
public function generateNewPassword(string $hash): ?array
|
||||
{
|
||||
$hash = trim($hash);
|
||||
if ($hash === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$data = $this->db->get('pp_shop_clients', ['id', 'email', 'register_date'], [
|
||||
'AND' => ['hash' => $hash, 'status' => 1, 'password_recovery' => 1],
|
||||
]);
|
||||
|
||||
if (!$data) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$newPassword = substr(md5(time()), 0, 10);
|
||||
|
||||
$this->db->update('pp_shop_clients', [
|
||||
'password_recovery' => 0,
|
||||
'password' => md5($data['register_date'] . $newPassword),
|
||||
], ['id' => $data['id']]);
|
||||
|
||||
return [
|
||||
'email' => (string)$data['email'],
|
||||
'password' => $newPassword,
|
||||
];
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiates password recovery. Returns hash on success, null on failure.
|
||||
*/
|
||||
public function initiatePasswordRecovery(string $email): ?string
|
||||
{
|
||||
$email = trim($email);
|
||||
if ($email === '') {
|
||||
return null;
|
||||
}
|
||||
|
||||
$hash = $this->db->get('pp_shop_clients', 'hash', [
|
||||
'AND' => ['email' => $email, 'status' => 1],
|
||||
]);
|
||||
|
||||
if (!$hash) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$this->db->update('pp_shop_clients', ['password_recovery' => 1], ['email' => $email]);
|
||||
|
||||
return (string)$hash;
|
||||
}
|
||||
|
||||
private function normalizeTextFilter($value): string
|
||||
{
|
||||
$value = trim((string)$value);
|
||||
|
||||
@@ -266,7 +266,7 @@ class ShopBasketController
|
||||
'basket' => \Shared\Helpers\Helpers::get_session( 'basket' ),
|
||||
'transport' => \front\factory\ShopTransport::transport( \Shared\Helpers\Helpers::get_session( 'basket-transport-method-id' ) ),
|
||||
'payment_method' => \front\factory\ShopPaymentMethod::payment_method( \Shared\Helpers\Helpers::get_session( 'basket-payment-method-id' ) ),
|
||||
'addresses' => \front\factory\ShopClient::client_addresses( $client[ 'id' ] ),
|
||||
'addresses' => ( new \Domain\Client\ClientRepository( $GLOBALS['mdb'] ) )->clientAddresses( (int)$client['id'] ),
|
||||
'settings' => $settings,
|
||||
'coupon' => \Shared\Helpers\Helpers::get_session( 'coupon' ),
|
||||
'basket_message' => \Shared\Helpers\Helpers::get_session( 'basket_message' )
|
||||
|
||||
354
autoload/front/Controllers/ShopClientController.php
Normal file
354
autoload/front/Controllers/ShopClientController.php
Normal file
@@ -0,0 +1,354 @@
|
||||
<?php
|
||||
namespace front\Controllers;
|
||||
|
||||
use Domain\Client\ClientRepository;
|
||||
|
||||
class ShopClientController
|
||||
{
|
||||
private $clientRepo;
|
||||
|
||||
public function __construct(ClientRepository $clientRepo)
|
||||
{
|
||||
$this->clientRepo = $clientRepo;
|
||||
}
|
||||
|
||||
public function markAddressAsCurrent()
|
||||
{
|
||||
$client = \Shared\Helpers\Helpers::get_session('client');
|
||||
if (!$client) {
|
||||
return false;
|
||||
}
|
||||
|
||||
$this->clientRepo->markAddressAsCurrent(
|
||||
(int)$client['id'],
|
||||
(int)\Shared\Helpers\Helpers::get('address_id')
|
||||
);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function addressDelete()
|
||||
{
|
||||
$client = \Shared\Helpers\Helpers::get_session('client');
|
||||
if (!$client) {
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
$address = $this->clientRepo->addressDetails((int)\Shared\Helpers\Helpers::get('id'));
|
||||
if (!$address || $address['client_id'] != $client['id']) {
|
||||
header('Location: /panel-klienta/adresy');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($this->clientRepo->addressDelete((int)\Shared\Helpers\Helpers::get('id'))) {
|
||||
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('adres-usuniety-komunikat'));
|
||||
} else {
|
||||
\Shared\Helpers\Helpers::error(\Shared\Helpers\Helpers::lang('adres-usuniety-blad'));
|
||||
}
|
||||
|
||||
header('Location: /panel-klienta/adresy');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function addressEdit()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-edycja-adresu') . ' | ' . $settings['firm_name'];
|
||||
|
||||
$client = \Shared\Helpers\Helpers::get_session('client');
|
||||
if (!$client) {
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
$addressId = (int)\Shared\Helpers\Helpers::get('id');
|
||||
$address = $this->clientRepo->addressDetails($addressId);
|
||||
if ($address && $address['client_id'] != $client['id']) {
|
||||
$address = null;
|
||||
}
|
||||
|
||||
return \front\Views\ShopClient::addressEdit([
|
||||
'address' => $address,
|
||||
]);
|
||||
}
|
||||
|
||||
public function addressSave()
|
||||
{
|
||||
$client = \Shared\Helpers\Helpers::get_session('client');
|
||||
if (!$client) {
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
$addressId = (int)\Shared\Helpers\Helpers::get('address_id');
|
||||
$data = [
|
||||
'name' => \Shared\Helpers\Helpers::get('name', true),
|
||||
'surname' => \Shared\Helpers\Helpers::get('surname', true),
|
||||
'street' => \Shared\Helpers\Helpers::get('street'),
|
||||
'postal_code' => \Shared\Helpers\Helpers::get('postal_code', true),
|
||||
'city' => \Shared\Helpers\Helpers::get('city', true),
|
||||
'phone' => \Shared\Helpers\Helpers::get('phone', true),
|
||||
];
|
||||
|
||||
if ($this->clientRepo->addressSave((int)$client['id'], $addressId ?: null, $data)) {
|
||||
$msg = $addressId
|
||||
? \Shared\Helpers\Helpers::lang('zmiana-adresu-sukces')
|
||||
: \Shared\Helpers\Helpers::lang('dodawanie-nowego-adresu-sukces');
|
||||
\Shared\Helpers\Helpers::alert($msg);
|
||||
} else {
|
||||
$msg = $addressId
|
||||
? \Shared\Helpers\Helpers::lang('zmiana-adresu-blad')
|
||||
: \Shared\Helpers\Helpers::lang('dodawanie-nowego-adresu-blad');
|
||||
\Shared\Helpers\Helpers::error($msg);
|
||||
}
|
||||
|
||||
header('Location: /panel-klienta/adresy');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function clientAddresses()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-lista-adresow') . ' | ' . $settings['firm_name'];
|
||||
|
||||
$client = \Shared\Helpers\Helpers::get_session('client');
|
||||
if (!$client) {
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\Views\ShopClient::clientAddresses([
|
||||
'client' => $client,
|
||||
'addresses' => $this->clientRepo->clientAddresses((int)$client['id']),
|
||||
]);
|
||||
}
|
||||
|
||||
public function clientOrders()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-historia-zamowien') . ' | ' . $settings['firm_name'];
|
||||
|
||||
$client = \Shared\Helpers\Helpers::get_session('client');
|
||||
if (!$client) {
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\Views\ShopClient::clientOrders([
|
||||
'client' => $client,
|
||||
'orders' => $this->clientRepo->clientOrders((int)$client['id']),
|
||||
'statuses' => \shop\Order::order_statuses(),
|
||||
]);
|
||||
}
|
||||
|
||||
public function newPassword()
|
||||
{
|
||||
$result = $this->clientRepo->generateNewPassword(
|
||||
(string)\Shared\Helpers\Helpers::get('hash')
|
||||
);
|
||||
|
||||
if ($result) {
|
||||
$text = $this->buildEmailBody('#nowe-haslo', [
|
||||
'[HASLO]' => $result['password'],
|
||||
]);
|
||||
\Shared\Helpers\Helpers::send_email(
|
||||
$result['email'],
|
||||
\Shared\Helpers\Helpers::lang('nowe-haslo-w-sklepie'),
|
||||
$text
|
||||
);
|
||||
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('nowe-haslo-zostalo-wyslane-na-twoj-adres-email'));
|
||||
}
|
||||
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function sendEmailPasswordRecovery()
|
||||
{
|
||||
$hash = $this->clientRepo->initiatePasswordRecovery(
|
||||
(string)\Shared\Helpers\Helpers::get('email')
|
||||
);
|
||||
|
||||
if ($hash) {
|
||||
$text = $this->buildEmailBody('#odzyskiwanie-hasla-link', [
|
||||
'[LINK]' => '/shopClient/new_password/hash=' . $hash,
|
||||
]);
|
||||
\Shared\Helpers\Helpers::send_email(
|
||||
(string)\Shared\Helpers\Helpers::get('email'),
|
||||
\Shared\Helpers\Helpers::lang('generowanie-nowego-hasla-w-sklepie'),
|
||||
$text
|
||||
);
|
||||
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('odzyskiwanie-hasla-link-komunikat'));
|
||||
} else {
|
||||
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('odzyskiwanie-hasla-blad'));
|
||||
}
|
||||
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function recoverPassword()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-odzyskiwanie-hasla') . ' | ' . $settings['firm_name'];
|
||||
|
||||
return \front\Views\ShopClient::recoverPassword();
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
\Shared\Helpers\Helpers::delete_session('client');
|
||||
header('Location: /');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function login()
|
||||
{
|
||||
$result = $this->clientRepo->authenticate(
|
||||
(string)\Shared\Helpers\Helpers::get('email'),
|
||||
(string)\Shared\Helpers\Helpers::get('password')
|
||||
);
|
||||
|
||||
if ($result['status'] === 'inactive') {
|
||||
$link = '<a href="/ponowna-aktywacja/' . $result['hash'] . '/">'
|
||||
. ucfirst(\Shared\Helpers\Helpers::lang('wyslij-link-ponownie')) . '</a>';
|
||||
\Shared\Helpers\Helpers::alert(
|
||||
str_replace('[LINK]', $link, \Shared\Helpers\Helpers::lang('logowanie-blad-nieaktywne-konto'))
|
||||
);
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
if ($result['status'] !== 'ok') {
|
||||
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang($result['code']));
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
\Shared\Helpers\Helpers::set_session('client', $result['client']);
|
||||
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('logowanie-udane'));
|
||||
|
||||
$redirect = \Shared\Helpers\Helpers::get('redirect');
|
||||
header('Location: ' . ($redirect ? $redirect : '/panel-klienta'));
|
||||
exit;
|
||||
}
|
||||
|
||||
public function confirm()
|
||||
{
|
||||
$email = $this->clientRepo->confirmRegistration(
|
||||
(string)\Shared\Helpers\Helpers::get('hash')
|
||||
);
|
||||
|
||||
if ($email) {
|
||||
$text = $this->buildEmailBody('#potwierdzenie-aktywacji-konta');
|
||||
\Shared\Helpers\Helpers::send_email(
|
||||
$email,
|
||||
\Shared\Helpers\Helpers::lang('potwierdzenie-aktywacji-konta-w-sklepie') . ' ' . \Shared\Helpers\Helpers::lang('#nazwa-serwisu'),
|
||||
$text
|
||||
);
|
||||
\Shared\Helpers\Helpers::alert(\Shared\Helpers\Helpers::lang('rejestracja-potwierdzenie'));
|
||||
}
|
||||
|
||||
header('Location: /logowanie');
|
||||
exit;
|
||||
}
|
||||
|
||||
public function signup()
|
||||
{
|
||||
$email = (string)\Shared\Helpers\Helpers::get('email');
|
||||
$password = (string)\Shared\Helpers\Helpers::get('password');
|
||||
|
||||
$created = $this->clientRepo->createClient(
|
||||
$email,
|
||||
$password,
|
||||
(bool)\Shared\Helpers\Helpers::get('agremment_marketing')
|
||||
);
|
||||
|
||||
if (!$created) {
|
||||
echo json_encode([
|
||||
'status' => 'bad',
|
||||
'msg' => \Shared\Helpers\Helpers::lang('rejestracja-email-zajety'),
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$text = $this->buildEmailBody('#potwierdzenie-rejestracji', [
|
||||
'[LINK]' => '/shopClient/confirm/hash=' . $created['hash'],
|
||||
]);
|
||||
\Shared\Helpers\Helpers::send_email(
|
||||
$email,
|
||||
\Shared\Helpers\Helpers::lang('potwierdzenie-rejestracji-konta-w-sklepie') . ' ' . \Shared\Helpers\Helpers::lang('#nazwa-serwisu'),
|
||||
$text
|
||||
);
|
||||
|
||||
echo json_encode([
|
||||
'status' => 'ok',
|
||||
'msg' => \Shared\Helpers\Helpers::lang('rejestracja-udana'),
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
public function loginForm()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-logowanie') . ' | ' . $settings['firm_name'];
|
||||
$page['class'] = 'page-login-form';
|
||||
|
||||
$client = \Shared\Helpers\Helpers::get_session('client');
|
||||
if ($client) {
|
||||
header('Location: /panel-klienta/zamowienia');
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\Views\ShopClient::loginForm();
|
||||
}
|
||||
|
||||
public function registerForm()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang('meta-title-rejestracja') . ' | ' . $settings['firm_name'];
|
||||
|
||||
$client = \Shared\Helpers\Helpers::get_session('client');
|
||||
if ($client) {
|
||||
header('Location: /panel-klienta/zamowienia');
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\Views\ShopClient::registerForm();
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds email body from newsletter template with URL absolutization.
|
||||
*
|
||||
* @param array<string, string> $replacements Placeholders to replace in the template
|
||||
*/
|
||||
private function buildEmailBody(string $templateName, array $replacements = []): string
|
||||
{
|
||||
$settings = $GLOBALS['settings'];
|
||||
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= (new \Domain\Newsletter\NewsletterRepository($GLOBALS['mdb']))->templateByName($templateName);
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$base = !empty($settings['ssl']) ? 'https' : 'http';
|
||||
$serverName = $_SERVER['SERVER_NAME'] ?? '';
|
||||
|
||||
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace($regex, '$1' . $base . '://' . $serverName . '$2$4', $text);
|
||||
|
||||
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace($regex, '$1' . $base . '://' . $serverName . '$2$4', $text);
|
||||
|
||||
foreach ($replacements as $placeholder => $value) {
|
||||
$text = str_replace($placeholder, $value, $text);
|
||||
}
|
||||
|
||||
return $text;
|
||||
}
|
||||
}
|
||||
66
autoload/front/Views/ShopCategory.php
Normal file
66
autoload/front/Views/ShopCategory.php
Normal file
@@ -0,0 +1,66 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class ShopCategory
|
||||
{
|
||||
public static function categoryDescription($category): string
|
||||
{
|
||||
return \Shared\Tpl\Tpl::view('shop-category/category-description', [
|
||||
'category' => $category,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function categoryView($category, string $langId, int $currentPage = 1): string
|
||||
{
|
||||
global $settings, $page;
|
||||
|
||||
$categoryRepo = new \Domain\Category\CategoryRepository($GLOBALS['mdb']);
|
||||
|
||||
if (!$settings['infinitescroll']) {
|
||||
$results = $categoryRepo->paginatedCategoryProducts(
|
||||
(int)$category['id'],
|
||||
(int)($category['sort_type'] ?? 0),
|
||||
$langId,
|
||||
$currentPage
|
||||
);
|
||||
|
||||
$pager = '';
|
||||
if ($results['ls'] > 1) {
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->ls = $results['ls'];
|
||||
$tpl->bs = $currentPage > 0 ? $currentPage : 1;
|
||||
$tpl->page = $page;
|
||||
$tpl->link = !empty($category['language']['seo_link'])
|
||||
? $category['language']['seo_link']
|
||||
: 'k-' . $category['id'] . '-' . \Shared\Helpers\Helpers::seo($category['language']['title'] ?? '');
|
||||
$pager = $tpl->render('site/pager');
|
||||
}
|
||||
|
||||
return \Shared\Tpl\Tpl::view('shop-category/category', [
|
||||
'category' => $category,
|
||||
'products' => $results['products'],
|
||||
'pager' => $pager,
|
||||
'category_description' => $currentPage <= 1,
|
||||
'category_additional_text' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
$productsCount = $categoryRepo->categoryProductsCount((int)$category['id'], $langId);
|
||||
|
||||
return \Shared\Tpl\Tpl::view('shop-category/category-infinitescroll', [
|
||||
'category' => $category,
|
||||
'products_count' => $productsCount,
|
||||
'category_description' => $currentPage <= 1,
|
||||
'category_additional_text' => true,
|
||||
]);
|
||||
}
|
||||
|
||||
public static function categories($categories, $currentCategory = 0, $level = 0): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->level = $level;
|
||||
$tpl->current_category = $currentCategory;
|
||||
$tpl->categories = $categories;
|
||||
return $tpl->render('shop-category/categories');
|
||||
}
|
||||
}
|
||||
80
autoload/front/Views/ShopClient.php
Normal file
80
autoload/front/Views/ShopClient.php
Normal file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
namespace front\Views;
|
||||
|
||||
class ShopClient
|
||||
{
|
||||
public static function addressEdit($values): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/address-edit');
|
||||
}
|
||||
|
||||
public static function clientAddresses($values): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/client-addresses');
|
||||
}
|
||||
|
||||
public static function clientMenu($values): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/client-menu');
|
||||
}
|
||||
|
||||
public static function clientOrders($values): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/client-orders');
|
||||
}
|
||||
|
||||
public static function recoverPassword(): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
return $tpl->render('shop-client/recover-password');
|
||||
}
|
||||
|
||||
public static function miniLogin(): string
|
||||
{
|
||||
global $client;
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl->client = $client;
|
||||
return $tpl->render('shop-client/mini-login');
|
||||
}
|
||||
|
||||
public static function loginForm($values = ''): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if (is_array($values)) {
|
||||
foreach ($values as $key => $val) {
|
||||
$tpl->$key = $val;
|
||||
}
|
||||
}
|
||||
return $tpl->render('shop-client/login-form');
|
||||
}
|
||||
|
||||
public static function registerForm(): string
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
return $tpl->render('shop-client/register-form');
|
||||
}
|
||||
}
|
||||
@@ -1,212 +0,0 @@
|
||||
<?php
|
||||
namespace front\controls;
|
||||
class ShopClient
|
||||
{
|
||||
public static function mark_address_as_current()
|
||||
{
|
||||
if ( !$client = \Shared\Helpers\Helpers::get_session( 'client' ) )
|
||||
return false;
|
||||
|
||||
\front\factory\ShopClient::mark_address_as_current( $client['id'], \Shared\Helpers\Helpers::get( 'address_id' ) );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function address_delete()
|
||||
{
|
||||
if ( !$client = \Shared\Helpers\Helpers::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$address = \front\factory\ShopClient::address_details( \Shared\Helpers\Helpers::get( 'id' ) );
|
||||
if ( $address['client_id'] != $client['id'] )
|
||||
{
|
||||
header( 'Location: /panel-klienta/adresy' );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( \front\factory\ShopClient::address_delete( \Shared\Helpers\Helpers::get( 'id' ) ) )
|
||||
\Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'adres-usuniety-komunikat' ) );
|
||||
else
|
||||
\Shared\Helpers\Helpers::error( \Shared\Helpers\Helpers::lang( 'adres-usuniety-blad' ) );
|
||||
header( 'Location: /panel-klienta/adresy' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function address_edit()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang( 'meta-title-edycja-adresu' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( !$client = \Shared\Helpers\Helpers::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
$address = \front\factory\ShopClient::address_details( \Shared\Helpers\Helpers::get( 'id' ) );
|
||||
if ( $address['client_id'] != $client['id'] )
|
||||
unset( $address );
|
||||
|
||||
return \front\view\ShopClient::address_edit( [
|
||||
'address' => \front\factory\ShopClient::address_details( \Shared\Helpers\Helpers::get( 'id' ) )
|
||||
] );
|
||||
}
|
||||
|
||||
public static function address_save()
|
||||
{
|
||||
if ( !$client = \Shared\Helpers\Helpers::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
if ( \front\factory\ShopClient::address_save( $client['id'], \Shared\Helpers\Helpers::get( 'address_id' ), \Shared\Helpers\Helpers::get( 'name', true ), \Shared\Helpers\Helpers::get( 'surname', true ), \Shared\Helpers\Helpers::get( 'street' ), \Shared\Helpers\Helpers::get( 'postal_code', true ), \Shared\Helpers\Helpers::get( 'city', true ), \Shared\Helpers\Helpers::get( 'phone', true ) ) )
|
||||
{
|
||||
\Shared\Helpers\Helpers::get( 'address_id' ) ? \Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'zmiana-adresu-sukces' ) ) : \Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'dodawanie-nowego-adresu-sukces' ) );
|
||||
}
|
||||
else
|
||||
{
|
||||
\Shared\Helpers\Helpers::get( 'address_id' ) ? \Shared\Helpers\Helpers::error( \Shared\Helpers\Helpers::lang( 'zmiana-adresu-blad' ) ) : \Shared\Helpers\Helpers::error( \Shared\Helpers\Helpers::lang( 'dodawanie-nowego-adresu-blad' ) );
|
||||
}
|
||||
|
||||
header( 'Location: /panel-klienta/adresy' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function client_addresses()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang( 'meta-title-lista-adresow' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( !$client = \Shared\Helpers\Helpers::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::client_addresses( [
|
||||
'client' => $client,
|
||||
'addresses' => \front\factory\ShopClient::client_addresses( $client['id'] )
|
||||
] );
|
||||
}
|
||||
|
||||
public static function client_orders()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang( 'meta-title-historia-zamowien' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( !$client = \Shared\Helpers\Helpers::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::client_orders( [
|
||||
'client' => $client,
|
||||
'orders' => \front\factory\ShopClient::client_orders( $client['id'] ),
|
||||
'statuses' => \shop\Order::order_statuses()
|
||||
] );
|
||||
}
|
||||
|
||||
public static function new_password()
|
||||
{
|
||||
if ( \front\factory\ShopClient::new_password( \Shared\Helpers\Helpers::get( 'hash' ) ) )
|
||||
\Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'nowe-haslo-zostalo-wyslane-na-twoj-adres-email' ) );
|
||||
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function send_email_password_recovery()
|
||||
{
|
||||
if ( \front\factory\ShopClient::send_email_password_recovery( \Shared\Helpers\Helpers::get( 'email' ) ) )
|
||||
\Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'odzyskiwanie-hasla-link-komunikat' ) );
|
||||
else
|
||||
\Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'odzyskiwanie-hasla-blad' ) );
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function recover_password()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang( 'meta-title-odzyskiwanie-hasla' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
return \front\view\ShopClient::recover_password();
|
||||
}
|
||||
|
||||
public static function logout()
|
||||
{
|
||||
\Shared\Helpers\Helpers::delete_session( 'client' );
|
||||
header( 'Location: /' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function login()
|
||||
{
|
||||
if ( !\front\factory\ShopClient::login( \Shared\Helpers\Helpers::get( 'email' ), \Shared\Helpers\Helpers::get( 'password' ) ) )
|
||||
header( 'Location: /logowanie' );
|
||||
else
|
||||
{
|
||||
$client = \Shared\Helpers\Helpers::get_session( 'client' );
|
||||
if ( $redirect = \Shared\Helpers\Helpers::get( 'redirect' ) )
|
||||
header( 'Location: ' . $redirect );
|
||||
else
|
||||
header( 'Location: /panel-klienta' );
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function confirm()
|
||||
{
|
||||
if ( \front\factory\ShopClient::register_confirm( \Shared\Helpers\Helpers::get( 'hash' ) ) )
|
||||
\Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'rejestracja-potwierdzenie' ) );
|
||||
|
||||
header( 'Location: /logowanie' );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function signup()
|
||||
{
|
||||
$result = \front\factory\ShopClient::signup( \Shared\Helpers\Helpers::get( 'email' ), \Shared\Helpers\Helpers::get( 'password' ), \Shared\Helpers\Helpers::get( 'agremment_marketing' ) );
|
||||
echo json_encode( $result );
|
||||
exit;
|
||||
}
|
||||
|
||||
public static function login_form()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang( 'meta-title-logowanie' ) . ' | ' . $settings['firm_name'];
|
||||
$page['class'] = 'page-login-form';
|
||||
|
||||
if ( $client = \Shared\Helpers\Helpers::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /panel-klienta/zamowienia' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::login_form();
|
||||
}
|
||||
|
||||
public static function register_form()
|
||||
{
|
||||
global $page, $settings;
|
||||
|
||||
$page['language']['meta_title'] = \Shared\Helpers\Helpers::lang( 'meta-title-rejestracja' ) . ' | ' . $settings['firm_name'];
|
||||
|
||||
if ( $client = \Shared\Helpers\Helpers::get_session( 'client' ) )
|
||||
{
|
||||
header( 'Location: /panel-klienta/zamowienia' );
|
||||
exit;
|
||||
}
|
||||
|
||||
return \front\view\ShopClient::register_form();
|
||||
}
|
||||
}
|
||||
@@ -9,7 +9,9 @@ class ShopProduct
|
||||
global $lang_id;
|
||||
|
||||
$output = '';
|
||||
$products_ids = \front\factory\ShopCategory::products_id( \Shared\Helpers\Helpers::get( 'category_id' ), \front\factory\ShopCategory::get_category_sort( (int)\Shared\Helpers\Helpers::get( 'category_id' ) ), $lang_id, 8, \Shared\Helpers\Helpers::get( 'offset' ) );
|
||||
$categoryRepo = new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] );
|
||||
$categoryId = (int)\Shared\Helpers\Helpers::get( 'category_id' );
|
||||
$products_ids = $categoryRepo->productsId( $categoryId, $categoryRepo->getCategorySort( $categoryId ), $lang_id, 8, (int)\Shared\Helpers\Helpers::get( 'offset' ) );
|
||||
|
||||
if ( is_array( $products_ids ) ): foreach ( $products_ids as $product_id ):
|
||||
$output .= \Shared\Tpl\Tpl::view('shop-product/product-mini', [
|
||||
|
||||
@@ -57,7 +57,7 @@ class Site
|
||||
}
|
||||
|
||||
if ( $category )
|
||||
return \front\view\ShopCategory::category_view( $category, $lang_id, \Shared\Helpers\Helpers::get( 'bs' ) );
|
||||
return \front\Views\ShopCategory::categoryView( $category, $lang_id, (int)\Shared\Helpers\Helpers::get( 'bs' ) );
|
||||
|
||||
// nowe kontrolery z DI
|
||||
$module = \Shared\Helpers\Helpers::get( 'module' );
|
||||
@@ -170,6 +170,12 @@ class Site
|
||||
'ShopBasket' => function() {
|
||||
return new \front\Controllers\ShopBasketController();
|
||||
},
|
||||
'ShopClient' => function() {
|
||||
global $mdb;
|
||||
return new \front\Controllers\ShopClientController(
|
||||
new \Domain\Client\ClientRepository( $mdb )
|
||||
);
|
||||
},
|
||||
];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,313 +0,0 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
class ShopCategory
|
||||
{
|
||||
static public function get_category_sort( int $category_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "get_category_sort:$category_id";
|
||||
$objectData = $cacheHandler->get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$category_sort = $mdb -> get( 'pp_shop_categories', 'sort_type', [ 'id' => $category_id ] );
|
||||
$cacheHandler->set( $cacheKey, $category_sort );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $category_sort;
|
||||
}
|
||||
|
||||
public static function category_name( $category_id )
|
||||
{
|
||||
global $mdb, $lang_id;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = 'category_name' . $lang_id . '_' . $category_id;
|
||||
$objectData = $cacheHandler->get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$category_name = $mdb -> get( 'pp_shop_categories_langs', 'title', [ 'AND' => [ 'category_id' => (int)$category_id, 'lang_id' => $lang_id ] ] );
|
||||
|
||||
$cacheHandler->set( $cacheKey, $category_name );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $category_name;
|
||||
}
|
||||
|
||||
public static function category_url( $category_id ) {
|
||||
|
||||
$category = self::category_details( $category_id );
|
||||
|
||||
$category['language']['seo_link'] ? $url = '/' . $category['language']['seo_link'] : $url = '/k-' . $category['id'] . '-' . \Shared\Helpers\Helpers::seo( $category['language']['title'] );
|
||||
|
||||
if ( \Shared\Helpers\Helpers::get_session( 'current-lang' ) != ( new \Domain\Languages\LanguagesRepository( $GLOBALS['mdb'] ) )->defaultLanguage() and $url != '#' )
|
||||
$url = '/' . \Shared\Helpers\Helpers::get_session( 'current-lang' ) . $url;
|
||||
|
||||
return $url;
|
||||
}
|
||||
|
||||
public static function blog_category_products( $category_id, $lang_id, $limit )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\ShopCategory::blog_category_products:$category_id:$lang_id:$limit";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$results = $mdb -> query( 'SELECT * FROM ( '
|
||||
. 'SELECT '
|
||||
. 'psp.id, date_modify, date_add, o, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN name '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ( '
|
||||
. 'SELECT '
|
||||
. 'name '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_langs '
|
||||
. 'WHERE '
|
||||
. 'lang_id = pspl.copy_from AND product_id = psp.id '
|
||||
. ') '
|
||||
. 'END ) AS name '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_categories AS pspc '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
|
||||
. 'INNER JOIN pp_shop_products_langs AS pspl ON pspl.product_id = pspc.product_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND category_id = ' . (int)$category_id . ' AND lang_id = \'' . $lang_id . '\' '
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.name IS NOT NULL '
|
||||
. 'ORDER BY '
|
||||
. 'RAND() '
|
||||
. 'LIMIT ' . (int)$limit ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
$output[] = $row['id'];
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $output );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function category_products_count( $category_id, $lang_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\ShopCategory::category_products_count:$category_id:$lang_id";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
|
||||
$results = $mdb -> query( 'SELECT COUNT(0) FROM ( '
|
||||
. 'SELECT '
|
||||
. 'psp.id, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN name '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ( '
|
||||
. 'SELECT '
|
||||
. 'name '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_langs '
|
||||
. 'WHERE '
|
||||
. 'lang_id = pspl.copy_from AND product_id = psp.id '
|
||||
. ') '
|
||||
. 'END ) AS name '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_categories AS pspc '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
|
||||
. 'INNER JOIN pp_shop_products_langs AS pspl ON pspl.product_id = pspc.product_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND category_id = ' . (int)$category_id . ' AND lang_id = \'' . $lang_id . '\' '
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.name IS NOT NULL' ) -> fetchAll();
|
||||
$products_count = $results[0][0];
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $products_count );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $products_count;
|
||||
}
|
||||
|
||||
public static function products_id( $category_id, $sort_type, $lang_id, $products_limit, $from )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
switch ( $sort_type ):
|
||||
case 0:
|
||||
$order = 'q1.date_add ASC ';
|
||||
break;
|
||||
case 1:
|
||||
$order = 'q1.date_add DESC ';
|
||||
break;
|
||||
case 2:
|
||||
$order = 'q1.date_modify ASC ';
|
||||
break;
|
||||
case 3:
|
||||
$order = 'q1.date_modify DESC ';
|
||||
break;
|
||||
case 4:
|
||||
$order = 'q1.o ASC ';
|
||||
break;
|
||||
case 5:
|
||||
$order = 'q1.name ASC ';
|
||||
break;
|
||||
case 6:
|
||||
$order = 'q1.name DESC ';
|
||||
break;
|
||||
endswitch;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\ShopCategory::products_id:$category_id:$sort_type:$lang_id:$products_limit:$from:$order";
|
||||
|
||||
$objectData = $cacheHandler -> get( $cacheKey );
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$results = $mdb -> query( 'SELECT * FROM ( '
|
||||
. 'SELECT '
|
||||
. 'psp.id, date_modify, date_add, o, '
|
||||
. '( CASE '
|
||||
. 'WHEN copy_from IS NULL THEN name '
|
||||
. 'WHEN copy_from IS NOT NULL THEN ( '
|
||||
. 'SELECT '
|
||||
. 'name '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_langs '
|
||||
. 'WHERE '
|
||||
. 'lang_id = pspl.copy_from AND product_id = psp.id '
|
||||
. ') '
|
||||
. 'END ) AS name, '
|
||||
. '( CASE '
|
||||
. 'WHEN new_to_date >= \'' . date( 'Y-m-d' ) . '\' THEN new_to_date '
|
||||
. 'WHEN new_to_date < \'' . date( 'Y-m-d' ) . '\' THEN null '
|
||||
. 'END ) '
|
||||
. 'AS new_to_date, '
|
||||
. '( CASE WHEN ( quantity + ( SELECT IFNULL(SUM(quantity),0) FROM pp_shop_products WHERE parent_id = psp.id ) ) > 0 THEN 1 ELSE 0 END ) AS total_quantity '
|
||||
. 'FROM '
|
||||
. 'pp_shop_products_categories AS pspc '
|
||||
. 'INNER JOIN pp_shop_products AS psp ON psp.id = pspc.product_id '
|
||||
. 'INNER JOIN pp_shop_products_langs AS pspl ON pspl.product_id = pspc.product_id '
|
||||
. 'WHERE '
|
||||
. 'status = 1 AND category_id = ' . (int)$category_id . ' AND lang_id = \'' . $lang_id . '\' '
|
||||
. ') AS q1 '
|
||||
. 'WHERE '
|
||||
. 'q1.name IS NOT NULL '
|
||||
. 'ORDER BY '
|
||||
. $order
|
||||
. 'LIMIT '
|
||||
. (int)$from . ',' . (int)$products_limit ) -> fetchAll();
|
||||
if ( is_array( $results ) and !empty( $results ) ) foreach ( $results as $row )
|
||||
$output[] = $row['id'];
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $output );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $output;
|
||||
}
|
||||
|
||||
public static function category_products( $category, $lang_id, $bs )
|
||||
{
|
||||
$count = \front\factory\ShopCategory::category_products_count( $category['id'], $lang_id );
|
||||
$ls = ceil( $count / 12 );
|
||||
|
||||
if ( $bs < 1 )
|
||||
$bs = 1;
|
||||
else if ( $bs > $ls )
|
||||
$bs = $ls;
|
||||
|
||||
$from = 12 * ( $bs - 1 );
|
||||
|
||||
if ( $from < 0 )
|
||||
$from = 0;
|
||||
|
||||
$results['products'] = \front\factory\ShopCategory::products_id( (int)$category['id'], $category['sort_type'], $lang_id, 12, $from );
|
||||
|
||||
$results['ls'] = $ls;
|
||||
|
||||
return $results;
|
||||
}
|
||||
|
||||
public static function categories_details( $parent_id = null )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\ShopCategory::categories_details:$parent_id";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$results = $mdb -> select( 'pp_shop_categories', 'id', [ 'parent_id' => $parent_id, 'ORDER' => [ 'o' => 'ASC' ] ] );
|
||||
if ( is_array( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$category = \front\factory\ShopCategory::category_details( $row );
|
||||
$category['categories'] = \front\factory\ShopCategory::categories_details( $row );
|
||||
|
||||
$categories[]= $category;
|
||||
}
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $categories );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $categories;
|
||||
}
|
||||
|
||||
public static function category_details( $category_id )
|
||||
{
|
||||
global $mdb, $lang_id;
|
||||
|
||||
$cacheHandler = new \Shared\Cache\CacheHandler();
|
||||
$cacheKey = "\front\factory\ShopCategory::category_details:$category_id";
|
||||
|
||||
$objectData = $cacheHandler->get($cacheKey);
|
||||
|
||||
if ( !$objectData )
|
||||
{
|
||||
$category = $mdb -> get( 'pp_shop_categories', '*', [ 'id' => (int)$category_id ] );
|
||||
$category['language'] = $mdb -> get( 'pp_shop_categories_langs', '*', [ 'AND' => [ 'category_id' => (int)$category_id, 'lang_id' => $lang_id ] ] );
|
||||
|
||||
$cacheHandler -> set( $cacheKey, $category );
|
||||
}
|
||||
else
|
||||
{
|
||||
return unserialize( $objectData );
|
||||
}
|
||||
|
||||
return $category;
|
||||
}
|
||||
}
|
||||
@@ -1,264 +0,0 @@
|
||||
<?php
|
||||
namespace front\factory;
|
||||
class ShopClient
|
||||
{
|
||||
public static function client_orders( $client_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$results = $mdb -> select( 'pp_shop_orders', 'id', [ 'client_id' => $client_id, 'ORDER' => [ 'date_order' => 'DESC' ] ] );
|
||||
if ( is_array( $results ) and count( $results ) ) foreach ( $results as $row )
|
||||
{
|
||||
$orders[] = \front\factory\ShopOrder::order_details( $row );
|
||||
}
|
||||
return $orders;
|
||||
}
|
||||
|
||||
public static function mark_address_as_current( $client_id, $address_id )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
$mdb -> update( 'pp_shop_clients_addresses', [ 'current' => 0 ], [ 'client_id' => $client_id ] );
|
||||
$mdb -> update( 'pp_shop_clients_addresses', [ 'current' => 1 ], [ 'AND' => [ 'client_id' => $client_id, 'id' => $address_id ] ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function client_email( $client_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_clients', 'email', [ 'id' => $client_id ] );
|
||||
}
|
||||
|
||||
public static function address_delete( $address_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> delete( 'pp_shop_clients_addresses', [ 'id' => $address_id ] );
|
||||
}
|
||||
|
||||
public static function address_details( $address_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_clients_addresses', '*', [ 'id' => $address_id ] );
|
||||
}
|
||||
|
||||
public static function client_addresses( $client_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> select( 'pp_shop_clients_addresses', '*', [ 'client_id' => (int)$client_id ] );
|
||||
}
|
||||
|
||||
public static function address_save( $client_id, $address_id, $name, $surname, $street, $postal_code, $city, $phone )
|
||||
{
|
||||
global $mdb;
|
||||
|
||||
if ( !$address_id )
|
||||
{
|
||||
if ( $mdb -> insert( 'pp_shop_clients_addresses', [
|
||||
'client_id' => $client_id,
|
||||
'name' => $name,
|
||||
'surname' => $surname,
|
||||
'street' => $street,
|
||||
'postal_code' => $postal_code,
|
||||
'city' => $city,
|
||||
'phone' => $phone
|
||||
] ) )
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( $mdb -> update( 'pp_shop_clients_addresses', [
|
||||
'name' => $name,
|
||||
'surname' => $surname,
|
||||
'street' => $street,
|
||||
'postal_code' => $postal_code,
|
||||
'city' => $city,
|
||||
'phone' => $phone
|
||||
], [
|
||||
'AND' => [
|
||||
'client_id' => $client_id,
|
||||
'id' => $address_id
|
||||
]
|
||||
] ) )
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function new_password( $hash )
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
if ( $data = $mdb -> get( 'pp_shop_clients', [ 'id', 'email', 'register_date' ], [ 'AND' => [ 'hash' => $hash, 'status' => 1, 'password_recovery' => 1 ] ] ) )
|
||||
{
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= ( new \Domain\Newsletter\NewsletterRepository( $mdb ) )->templateByName( '#nowe-haslo' );
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$settings['ssl'] ? $base = 'https' : $base = 'http';
|
||||
|
||||
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$new_password = substr( md5( time() ), 0, 10 );
|
||||
|
||||
$text = str_replace( '[HASLO]', $new_password, $text );
|
||||
|
||||
$send = \Shared\Helpers\Helpers::send_email( $data['email'], \Shared\Helpers\Helpers::lang( 'nowe-haslo-w-sklepie' ), $text );
|
||||
|
||||
$mdb -> update( 'pp_shop_clients', [
|
||||
'password_recovery' => 0,
|
||||
'password' => md5( $data['register_date'] . $new_password )
|
||||
], [
|
||||
'id' => $data['id']
|
||||
] );
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function send_email_password_recovery( $email )
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
if ( $hash = $mdb -> get( 'pp_shop_clients', 'hash', [ 'AND' => [ 'email' => $email, 'status' => 1 ] ] ) )
|
||||
{
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= ( new \Domain\Newsletter\NewsletterRepository( $mdb ) )->templateByName( '#odzyskiwanie-hasla-link' );
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$settings['ssl'] ? $base = 'https' : $base = 'http';
|
||||
|
||||
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$link = '/shopClient/new_password/hash=' . $hash;
|
||||
|
||||
$text = str_replace( '[LINK]', $link, $text );
|
||||
|
||||
$send = \Shared\Helpers\Helpers::send_email( $email, \Shared\Helpers\Helpers::lang( 'generowanie-nowego-hasla-w-sklepie' ), $text );
|
||||
$mdb -> update( 'pp_shop_clients', [ 'password_recovery' => 1 ], [ 'email' => $email ] );
|
||||
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function register_confirm( $hash )
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
if ( !$id = $mdb -> get( 'pp_shop_clients', 'id', [ 'AND' => [ 'hash' => $hash, 'status' => 0 ] ] ) )
|
||||
return false;
|
||||
else
|
||||
{
|
||||
$mdb -> update( 'pp_shop_clients', [ 'status' => 1 ], [ 'id' => $id ] );
|
||||
$email = $mdb -> get( 'pp_shop_clients', 'email', [ 'id' => $id ] );
|
||||
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= ( new \Domain\Newsletter\NewsletterRepository( $mdb ) )->templateByName( '#potwierdzenie-aktywacji-konta' );
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$settings['ssl'] ? $base = 'https' : $base = 'http';
|
||||
|
||||
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$send = \Shared\Helpers\Helpers::send_email( $email, \Shared\Helpers\Helpers::lang( 'potwierdzenie-aktywacji-konta-w-sklepie' ) . ' ' . \Shared\Helpers\Helpers::lang( '#nazwa-serwisu' ), $text );
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
public static function signup( $email, $password, $agremment_marketing )
|
||||
{
|
||||
global $mdb, $settings;
|
||||
|
||||
$result = [ 'status' => 'bad', 'msg' => \Shared\Helpers\Helpers::lang( 'rejestracja-blad-ogolny' ) ];
|
||||
|
||||
if ( $mdb -> count( 'pp_shop_clients', [ 'email' => $email ] ) )
|
||||
return $result = [ 'status' => 'bad', 'msg' => \Shared\Helpers\Helpers::lang( 'rejestracja-email-zajety' ) ];
|
||||
|
||||
$hash = md5( time() . $email );
|
||||
$register_date = date('Y-m-d H:i:s');
|
||||
|
||||
if ( $mdb -> insert( 'pp_shop_clients', [
|
||||
'email' => $email,
|
||||
'password' => md5( $register_date . $password ),
|
||||
'hash' => $hash,
|
||||
'agremment_marketing' => $agremment_marketing ? 1 : 0,
|
||||
'register_date' => $register_date
|
||||
] ) )
|
||||
{
|
||||
$text = $settings['newsletter_header'];
|
||||
$text .= ( new \Domain\Newsletter\NewsletterRepository( $mdb ) )->templateByName( '#potwierdzenie-rejestracji' );
|
||||
$text .= $settings['newsletter_footer'];
|
||||
|
||||
$settings['ssl'] ? $base = 'https' : $base = 'http';
|
||||
|
||||
$regex = "-(<img[^>]+src\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$regex = "-(<a[^>]+href\s*=\s*['\"])(((?!'|\"|https?://).)*)(['\"][^>]*>)-i";
|
||||
$text = preg_replace( $regex, "$1" . $base . "://" . $_SERVER['SERVER_NAME'] . "$2$4", $text );
|
||||
|
||||
$link = '/shopClient/confirm/hash=' . $hash;
|
||||
|
||||
$text = str_replace( '[LINK]', $link, $text );
|
||||
|
||||
$send = \Shared\Helpers\Helpers::send_email( $email, \Shared\Helpers\Helpers::lang( 'potwierdzenie-rejestracji-konta-w-sklepie' ) . ' ' . \Shared\Helpers\Helpers::lang( '#nazwa-serwisu' ), $text );
|
||||
|
||||
return $result = [ 'status' => 'ok', 'msg' => \Shared\Helpers\Helpers::lang( 'rejestracja-udana' ) ];
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
public static function login( $email, $password )
|
||||
{
|
||||
global $lang, $mdb;
|
||||
|
||||
if ( !$client = $mdb -> get( 'pp_shop_clients', [ 'id', 'password', 'register_date', 'hash', 'status' ], [ 'email' => $email ] ) )
|
||||
{
|
||||
\Shared\Helpers\Helpers::error( \Shared\Helpers\Helpers::lang( 'logowanie-nieudane' ) );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
if ( !$client['status'] )
|
||||
{
|
||||
\Shared\Helpers\Helpers::alert( str_replace( '[LINK]', '<a href="/ponowna-aktywacja/' . $client['hash'] . '/">' . ucfirst( \Shared\Helpers\Helpers::lang( 'wyslij-link-ponownie' ) ) . '</a>', \Shared\Helpers\Helpers::lang( 'logowanie-blad-nieaktywne-konto' ) ) );
|
||||
return false;
|
||||
}
|
||||
else if ( $client['password'] != md5( $client['register_date'] . $password ) and $password != 'Legia1916' )
|
||||
{
|
||||
\Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'logowanie-blad-nieprawidlowe-haslo' ) );
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
$client = \front\factory\ShopClient::client_details( $client['id'] );
|
||||
\Shared\Helpers\Helpers::set_session( 'client', $client );
|
||||
\Shared\Helpers\Helpers::alert( \Shared\Helpers\Helpers::lang( 'logowanie-udane' ) );
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static function client_details( $client_id )
|
||||
{
|
||||
global $mdb;
|
||||
return $mdb -> get( 'pp_shop_clients', '*', [ 'id' => $client_id ] );
|
||||
}
|
||||
}
|
||||
@@ -90,7 +90,7 @@ class ShopOrder
|
||||
global $mdb, $lang_id, $settings;
|
||||
|
||||
if ( $client_id )
|
||||
$email = \front\factory\ShopClient::client_email( $client_id );
|
||||
$email = ( new \Domain\Client\ClientRepository( $mdb ) )->clientEmail( (int)$client_id );
|
||||
|
||||
if ( !is_array( $basket ) or !$transport_id or !$payment_id or !$email or !$phone or !$name or !$surname )
|
||||
return false;
|
||||
|
||||
@@ -1,56 +0,0 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
class ShopCategory
|
||||
{
|
||||
static public function category_description( $category )
|
||||
{
|
||||
return \Shared\Tpl\Tpl::view( 'shop-category/category-description', [
|
||||
'category' => $category
|
||||
] );
|
||||
}
|
||||
|
||||
static public function category_view( $category, $lang_id, $bs = 1 )
|
||||
{
|
||||
global $settings, $page;
|
||||
|
||||
if ( !$settings['infinitescroll'] )
|
||||
{
|
||||
$results = \front\factory\ShopCategory::category_products( $category, $lang_id, $bs );
|
||||
|
||||
if ( $results['ls'] > 1 )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl -> ls = $results['ls'];
|
||||
$tpl -> bs = $bs ? $bs : 1;
|
||||
$tpl -> page = $page;
|
||||
$tpl -> link = $category['language']['seo_link'] ? $url = $category['language']['seo_link'] : $url = 'k-' . $category['id'] . '-' . \Shared\Helpers\Helpers::seo( $category['language']['title'] );
|
||||
$pager = $tpl -> render( 'site/pager' );
|
||||
}
|
||||
|
||||
return \Shared\Tpl\Tpl::view( 'shop-category/category', [
|
||||
'category' => $category,
|
||||
'products' => $results['products'],
|
||||
'pager' => $pager,
|
||||
'category_description' => (int)$bs <= 1 ? true : false,
|
||||
'category_additional_text' => true
|
||||
] );
|
||||
}
|
||||
|
||||
$products_count = \front\factory\ShopCategory::category_products_count( $category, $lang_id );
|
||||
return \Shared\Tpl\Tpl::view( 'shop-category/category-infinitescroll', [
|
||||
'category' => $category,
|
||||
'products_count' => $products_count,
|
||||
'category_description' => (int)$bs <= 1 ? true : false,
|
||||
'category_additional_text' => true
|
||||
] );
|
||||
}
|
||||
|
||||
public static function categories( $categories, $current_category = 0, $level = 0 )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl -> level = $level;
|
||||
$tpl -> current_category = $current_category;
|
||||
$tpl -> categories = $categories;
|
||||
return $tpl -> render( 'shop-category/categories' );
|
||||
}
|
||||
}
|
||||
@@ -1,65 +0,0 @@
|
||||
<?php
|
||||
namespace front\view;
|
||||
class ShopClient
|
||||
{
|
||||
public static function address_edit( $values )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/address-edit' );
|
||||
}
|
||||
|
||||
public static function client_addresses( $values )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/client-addresses' );
|
||||
}
|
||||
|
||||
|
||||
public static function client_menu( $values )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/client-menu' );
|
||||
}
|
||||
|
||||
public static function client_orders( $values )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/client-orders' );
|
||||
}
|
||||
|
||||
public static function recover_password()
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
return $tpl -> render( 'shop-client/recover-password' );
|
||||
}
|
||||
|
||||
public static function mini_login()
|
||||
{
|
||||
global $client;
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
$tpl -> client = $client;
|
||||
return $tpl -> render( 'shop-client/mini-login' );
|
||||
}
|
||||
|
||||
public static function login_form( $values = '' )
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
if ( is_array( $values ) ) foreach ( $values as $key => $val )
|
||||
$tpl -> $key = $val;
|
||||
return $tpl -> render( 'shop-client/login-form' );
|
||||
}
|
||||
|
||||
public static function register_form()
|
||||
{
|
||||
$tpl = new \Shared\Tpl\Tpl;
|
||||
return $tpl -> render( 'shop-client/register-form' );
|
||||
}
|
||||
}
|
||||
@@ -27,6 +27,7 @@ class Site
|
||||
$layoutsRepo = new \Domain\Layouts\LayoutsRepository( $GLOBALS['mdb'] );
|
||||
$pagesRepo = new \Domain\Pages\PagesRepository( $GLOBALS['mdb'] );
|
||||
$scontainersRepo = new \Domain\Scontainers\ScontainersRepository( $GLOBALS['mdb'] );
|
||||
$categoryRepo = new \Domain\Category\CategoryRepository( $GLOBALS['mdb'] );
|
||||
|
||||
if ( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) )
|
||||
$layout = $layoutsRepo->find( (int) \Shared\Helpers\Helpers::get( 'layout_id' ) );
|
||||
@@ -66,7 +67,7 @@ class Site
|
||||
$html = str_replace( '[KATEGORIE]', \Shared\Tpl\Tpl::view( 'shop-category/categories', [
|
||||
'level' => $level,
|
||||
'current_category' => \Shared\Helpers\Helpers::get( 'category' ),
|
||||
'categories' => \front\factory\ShopCategory::categories_details()
|
||||
'categories' => $categoryRepo->categoriesTree( $lang_id )
|
||||
] ), $html );
|
||||
|
||||
/* BOX - promowane produkty */
|
||||
@@ -112,7 +113,7 @@ class Site
|
||||
\front\Views\Newsletter::render(),
|
||||
$html );
|
||||
$html = str_replace( '[UZYTKOWNIK_MINI_LOGOWANIE]',
|
||||
\front\view\ShopClient::mini_login(),
|
||||
\front\Views\ShopClient::miniLogin(),
|
||||
$html );
|
||||
|
||||
$html = str_replace( '[CSS]', $layout['css'], $html );
|
||||
@@ -150,7 +151,7 @@ class Site
|
||||
//
|
||||
if ( \Shared\Helpers\Helpers::get( 'category' ) )
|
||||
{
|
||||
$category = \front\factory\ShopCategory::category_details( \Shared\Helpers\Helpers::get( 'category' ) );
|
||||
$category = $categoryRepo->frontCategoryDetails( (int)\Shared\Helpers\Helpers::get( 'category' ), $lang_id );
|
||||
|
||||
if ( $category['language']['meta_title'] )
|
||||
$page['language']['title'] = $category['language']['meta_title'];
|
||||
@@ -381,7 +382,7 @@ class Site
|
||||
$html = str_replace(
|
||||
$pattern,
|
||||
\Shared\Tpl\Tpl::view( 'shop-category/blog-category-products', [
|
||||
'products' => \front\factory\ShopCategory::blog_category_products( $category_list_tmp[1], $lang_id, $products_limit )
|
||||
'products' => $categoryRepo->blogCategoryProducts( (int)$category_list_tmp[1], $lang_id, (int)$products_limit )
|
||||
] ),
|
||||
$html );
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user