Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Merge branch 'master' of github.com:heimrichhannot/contao-isotope-bundle
Browse files Browse the repository at this point in the history
  • Loading branch information
Konstantin Wagner committed Aug 30, 2018
2 parents 2833f19 + f0894cd commit 0da4e0f
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,11 @@
# Changelog
All notable changes to this project will be documented in this file.

## [0.11.2] - 2018-08-29

#### Changed
* faster way to get copyrights and tags

## [DEV] - 2018-07-26

#### Fixed
Expand Down
14 changes: 10 additions & 4 deletions src/Backend/Callbacks.php
Expand Up @@ -12,6 +12,7 @@
use Contao\DataContainer;
use Contao\FilesModel;
use Contao\FrontendUser;
use Contao\StringUtil;
use Contao\System;
use Isotope\Frontend\ProductAction\Registry;
use Isotope\Model\Product;
Expand Down Expand Up @@ -103,13 +104,18 @@ public function getUploadedFiles($value, DataContainer $dc)

public function getLoadCallbackValueByField(string $field, $value, DataContainer $dc)
{
$productModel = System::getContainer()->get('contao.framework')->getAdapter(Product::class)->findByPk($dc->activeRecord->id);

if (null === $productModel) {
if (null === ($productModel = System::getContainer()->get('contao.framework')->getAdapter(Product::class)->findByPk($dc->activeRecord->id))) {
return $value;
}

return $productModel->$field;
// $values = StringUtil::deserialize($productModel->{$field});
//
// if(!empty($values))
// {
// return $values;
// }

return $productModel->{$field};
}

public function getUploadedDownloadFiles($value, DataContainer $dc)
Expand Down
20 changes: 13 additions & 7 deletions src/Helper/ProductHelper.php
Expand Up @@ -113,19 +113,25 @@ public function getTags($obj)
{
$options = [];

if (null === ($tags = $this->framework->getAdapter(ProductDataModel::class)->findBy(['tag IS NOT NULL'], null))) {
if (null === ($products = $this->framework->getAdapter(ProductDataModel::class)->findBy(['tag IS NOT NULL'], null))) {
return $options;
}

if (null === ($tags = $tags->fetchEach('tag'))) {
return $options;
}
$result = [];

foreach ($products as $product) {
if (!$product->tag || '' == $product->tag) {
continue;
}

$options = StringUtil::deserialize($product->tag, true);

foreach ($tags as $tag) {
$options = array_merge($options, StringUtil::deserialize($tag, true));
foreach ($options as $option) {
$result[] = $option;
}
}

return $options;
return array_filter(array_unique($result));
}

public function getCopyrights()
Expand Down
23 changes: 18 additions & 5 deletions src/Model/ProductModel.php
Expand Up @@ -9,6 +9,7 @@
namespace HeimrichHannot\IsotopeBundle\Model;

use Contao\Database;
use Contao\StringUtil;
use Contao\System;
use Isotope\Model\Product\Standard;
use Isotope\Model\ProductType;
Expand Down Expand Up @@ -131,14 +132,26 @@ public function __isset($key)
*/
public function getCopyrights()
{
/** @var Database\Result $copyrights */
$copyrights = System::getContainer()->get('contao.framework')->createInstance(Database::class)->prepare("SELECT * FROM tl_iso_product_data WHERE copyright IS NOT NULL AND copyright != ''")->execute();
if (null === ($products = System::getContainer()->get('contao.framework')->getAdapter(ProductDataModel::class)->findBy(['copyright IS NOT NULL'], null))) {
return [];
}

$result = [];

foreach ($products as $product) {
if (!$product->copyright || '' == $product->copyright) {
continue;
}

$options = StringUtil::deserialize($product->copyright, true);

if (null !== ($copyrights)) {
return array_unique($copyrights->fetchEach('copyright'));
foreach ($options as $option) {
$result[] = $option;
}
}

return [];
// do not use array_unique -> wrong copyright will be displayed as set copyright for this product
return $result;
}

public function getStock(int $id)
Expand Down

0 comments on commit 0da4e0f

Please sign in to comment.