Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# Changelog
## Unreleased
### Add
- Add cart button for product list

### Change
- Support tab navigation for search, suggest and paging components
- Upgrade Web Components version to v5.1.5
Expand Down
4 changes: 4 additions & 0 deletions assets/css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -814,3 +814,7 @@ ff-suggest .ff-popular-searches div {
background: #fff;
}

.ff-cart-btn {
margin-left: 10px;
}

22 changes: 15 additions & 7 deletions metadata.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
'http_article_feed' => Controller\ArticleFeedController::class,
'http_category_feed' => Controller\CategoryFeedController::class,
'http_suggest_category_feed' => Controller\SuggestCategoryFeedController::class,
'addtocart' => Controller\AddToCartController::class,
],
'extend' => [
ModuleConfiguration::class => \Omikron\FactFinder\Oxid\Controller\Admin\ModuleConfiguration::class,
Expand Down Expand Up @@ -91,20 +92,27 @@
// 'position' => $settingPosition++,
// ],
[
'group' => 'ffAdvanced',
'name' => 'ffTrackingAddToCartCount',
'type' => 'select',
'value' => 'count_selected_amount',
'constraints' => 'count_as_one|count_selected_amount',
'position' => $settingPosition++,
'group' => 'ffAdvanced',
'name' => 'ffSidAsUserId',
'type' => 'bool',
'value' => false,
'position' => $settingPosition++,
],
[
'group' => 'ffAdvanced',
'name' => 'ffSidAsUserId',
'name' => 'ffCartBtn',
'type' => 'bool',
'value' => false,
'position' => $settingPosition++,
],
[
'group' => 'ffAdvanced',
'name' => 'ffTrackingAddToCartCount',
'type' => 'select',
'value' => 'count_selected_amount',
'constraints' => 'count_as_one|count_selected_amount',
'position' => $settingPosition++,
],
[
'group' => 'ffFeatures',
'name' => 'ffUseForCategories',
Expand Down
55 changes: 55 additions & 0 deletions src/Controller/AddToCartController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
<?php

declare(strict_types=1);

namespace Omikron\FactFinder\Oxid\Controller;

use OxidEsales\Eshop\Application\Controller\FrontendController;
use OxidEsales\Eshop\Application\Model\Article;
use OxidEsales\Eshop\Core\Registry;

class AddToCartController extends FrontendController
{
public function addToCart(): void
{
$productNumber = Registry::getRequest()->getRequestParameter('productNumber');
$amount = 1;
$utilsView = Registry::getUtilsView();

try {
if (!$productNumber) {
throw new \Exception("Product with number $productNumber does not exist");
}

$product = oxNew(Article::class);
$productId = $this->getProductIdByNumber($productNumber);

if (!$productId || !$product->load($productId) || !$product->isBuyable()) {
throw new \Exception("Product with number $productNumber does not exist or is not buyable");
}

$basket = Registry::getSession()->getBasket();
$basket->addToBasket($productId, $amount);
$basket->calculateBasket(true);
$utilsView->addErrorToDisplay('Product was added to the cart successfully.');
$this->redirectToReferer();
} catch (\Exception $e) {
$utilsView->addErrorToDisplay('Error: ' . $e->getMessage(), false, false, 'error_message');
$this->redirectToReferer();
}
}

private function getProductIdByNumber($productNumber)
{
$database = \OxidEsales\Eshop\Core\DatabaseProvider::getDb();
$sQuery = 'SELECT oxid FROM oxarticles WHERE oxartnum = ? AND oxactive = 1';

return $database->getOne($sQuery, [$productNumber]);
}

private function redirectToReferer(): void
{
$referer = $_SERVER['HTTP_REFERER'] ?? Registry::getConfig()->getCurrentShopUrl();
Registry::getUtils()->redirect($referer, false, 302);
}
}
1 change: 1 addition & 0 deletions views/admin_twig/de/ffwebcomponents_de_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'SHOP_MODULE_ffTrackingAddToCartCount_count_selected_amount' => 'track single click with selected amount',
'SHOP_MODULE_ffUseProxy' => 'Proxy benutzen?',
'SHOP_MODULE_ffSidAsUserId' => 'Die SID als userId senden, wenn der Benutzer nicht angemeldet ist?',
'SHOP_MODULE_ffCartBtn' => 'Schaltfläche Warenkorb hinzufügen für die Produktliste',
'SHOP_MODULE_GROUP_ffFeatures' => 'Features Settings',
'SHOP_MODULE_ffUseForCategories' => 'Kategorieseiten mit FACT-Finder® rendern?',
'SHOP_MODULE_ffCategoryPathFieldName' => 'Kategoriepfad-Feldname',
Expand Down
1 change: 1 addition & 0 deletions views/admin_twig/en/ffwebcomponents_en_lang.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
'SHOP_MODULE_ffTrackingAddToCartCount_count_selected_amount' => 'track single click with selected amount',
'SHOP_MODULE_ffUseProxy' => 'Use Proxy?',
'SHOP_MODULE_ffSidAsUserId' => 'Send the SID as userId when user not logged in?',
'SHOP_MODULE_ffCartBtn' => 'Add cart button for product list',
'SHOP_MODULE_GROUP_ffFeatures' => 'Features Settings',
'SHOP_MODULE_ffUseForCategories' => 'Use FACT-Finder® for category pages?',
'SHOP_MODULE_ffCategoryPathFieldName' => 'Category Path field name',
Expand Down
23 changes: 10 additions & 13 deletions views/twig/webcomponents/widget/record_list.html.twig
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
<ff-record-list unresolved class="row gridView list-container" subscribe="{{ subscribe|default("true") }}">
<template data-role="record">
<ff-record class="productData col-xs-12 col-sm-6 col-md-4 productBox">
<form action="{{ oViewConf.getSelfActionLink()|escape }}" method="post">
<input type="hidden" name="cl" value="{{ oViewConf.getActiveClassName()|escape }}" />
<input type="hidden" name="fnc" value="tobasket" />
<div class="card product-card">
<div class="product-img-wrapper">
<a data-anchor="{{ '{{ masterValues.Deeplink }}' }}" data-redirect="{{ '{{ masterValues.Deeplink }}' }}" data-redirect-target="_self" title="{{ '{{ masterValues.Name }}' }}">
Expand All @@ -25,22 +22,22 @@
<div class="listDetails text-center">
<div class="actions text-center">
<div class="btn-group">

{# TODO Implement add to cart btn #}
{# <button type="submit" class="btn btn-default hasTooltip" data-placement="bottom"#}
{# title="" data-container="body"#}
{# data-original-title="{{ translate({ ident: "ADD_TO_CART" }) }}">#}
{# <svg>#}
{# <use xlink:href="#bag"></use>#}
{# </svg>#}
{# </button>#}
<a class="btn btn-primary" data-redirect="{{ '{{ masterValues.Deeplink }}' }}" data-redirect-target="_self" data-anchor="{{ '{{ masterValues.Deeplink }}' }}">{{ translate({ ident: "MORE_INFO" }) }}</a>

{% if oViewConf.getFFBoolConfigParam("ffCartBtn") %}
<form action="{{ oViewConf.getSelfActionLink()|raw }}" method="post" class="add-to-cart-form">
{{ oViewConf.getHiddenSid()|raw }}
<input type="hidden" name="cl" value="addToCart">
<input type="hidden" name="fnc" value="addToCart">
<input type="hidden" name="productNumber" value="{{ '{{ variantValues.0.ProductNumber }}' }}">
<button type="submit" class="btn btn-primary ff-cart-btn"> {{ translate({ ident: "TO_CART" }) }}</button>
</form>
{% endif %}
</div>
</div>
</div>
</div>
</div>
</form>
</ff-record>
</template>
</ff-record-list>
Expand Down
Loading