ver. 0.303: Fix attribute display collision + product preview button
Fix: product attributes with the same sort order value were overwriting each other in getProductAttributes(), causing only one attribute to display on the frontend. Now uses usort() with sequential keys. New: Preview button in product edit form opens product page in new tab. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3359,12 +3359,18 @@ class ProductRepository
|
||||
|
||||
$attributes = \Shared\Helpers\Helpers::removeDuplicates($attributes, 'id');
|
||||
|
||||
$sorted = [];
|
||||
$toSort = [];
|
||||
foreach ($attributes as $key => $val) {
|
||||
$row = [];
|
||||
$row['id'] = $key;
|
||||
$row['values'] = $val;
|
||||
$sorted[$attrRepo->getAttributeOrder((int) $key)] = $row;
|
||||
$toSort[] = ['order' => (int) $attrRepo->getAttributeOrder((int) $key), 'data' => $row];
|
||||
}
|
||||
usort($toSort, function ($a, $b) { return $a['order'] - $b['order']; });
|
||||
|
||||
$sorted = [];
|
||||
foreach ($toSort as $i => $item) {
|
||||
$sorted[$i + 1] = $item['data'];
|
||||
}
|
||||
|
||||
return $sorted;
|
||||
|
||||
@@ -547,6 +547,11 @@ class ShopProductController
|
||||
FormAction::cancel( $backUrl ),
|
||||
];
|
||||
|
||||
if ( $productId > 0 ) {
|
||||
$previewUrl = $this->repository->getProductUrl( $productId );
|
||||
$actions[] = FormAction::preview( $previewUrl );
|
||||
}
|
||||
|
||||
return new FormEditViewModel(
|
||||
'product-edit',
|
||||
$title,
|
||||
|
||||
@@ -56,6 +56,22 @@ class FormAction
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Predefiniowana akcja Podgląd (otwiera w nowej karcie)
|
||||
*/
|
||||
public static function preview(string $url, string $label = 'Podgląd'): self
|
||||
{
|
||||
return new self(
|
||||
'preview',
|
||||
$label,
|
||||
$url,
|
||||
null,
|
||||
'btn btn-info',
|
||||
'link',
|
||||
['target' => '_blank']
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* Predefiniowana akcja Anuluj
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user