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
30 changes: 15 additions & 15 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

40 changes: 37 additions & 3 deletions resources/js/cms-elements.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
* and `resources/js/elements.ts`). Hand-authored for the same reason as
* `window.d.ts`; keep in sync with `cms`'s `ElementIndexPage.vue`,
* `ElementEditor.vue`, `CpButtonLink.vue`, `ActionMenu.vue`, `common/types` and
* `useElementIndexVisits.ts`.
* `useElementIndexVisits.ts`, `useAppLayout.ts`, `useCustomizeSources.ts`.
*/
declare module '@craftcms/cms/elements' {
import type {DefineComponent} from 'vue';
import type {ComputedRef, DefineComponent} from 'vue';

export type IndexQueryValue =
| string
Expand Down Expand Up @@ -56,7 +56,41 @@ declare module '@craftcms/cms/elements' {
items: ActionItemLink[];
}

export type ActionItem = ActionItemLink | ActionItemGroup;
export interface ActionItemButton {
type?: 'button';
label: string;
icon?: string;
onClick?: (event: Event) => void;
}

export type ActionItem = ActionItemLink | ActionItemGroup | ActionItemButton;

export interface NavItem {
label: string | null;
href: string | null;
selected: boolean;
group: boolean;
subnav: NavItem[] | false;
}

export interface UseAppLayoutOptions {
subnav?: NavItem[];
subnavActions?: ActionItem[];
}

export function useAppLayout(
options: UseAppLayoutOptions | (() => UseAppLayoutOptions)
): void;

export interface CustomizeSourcesTarget {
elementType?: string | null;
page?: string | null;
sourceKey?: string | null;
}

export function useCustomizeSources(
target: () => CustomizeSourcesTarget
): ComputedRef<ActionItemButton[]>;

export const ActionMenu: DefineComponent<{
actions: ActionItem[];
Expand Down
18 changes: 18 additions & 0 deletions resources/js/pages/inventory/transfers/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
appendIndexQuery,
CpButtonLink,
ElementIndexPage,
useAppLayout,
useCustomizeSources,
type ElementIndexRoute,
type NavItem,
} from '@craftcms/cms/elements';

const props = defineProps<{
indexUrl: string;
newTransferUrl: string | null;
newTransferLabel: string;
sourceNavItems?: NavItem[];
elementType?: string | null;
page?: string | null;
source?: {key?: string | null} | null;
}>();

const subnavActions = useCustomizeSources(() => ({
elementType: props.elementType,
page: props.page,
sourceKey: props.source?.key,
}));

useAppLayout(() => ({
subnav: props.sourceNavItems ?? [],
subnavActions: subnavActions.value,
}));

// `indexUrl` carries the `site` param `Url::cpUrl()` adds, which the index
// query is merged over.
const route: ElementIndexRoute = {
Expand Down
18 changes: 18 additions & 0 deletions resources/js/pages/products/Index.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@
import {
appendIndexQuery,
ElementIndexPage,
useAppLayout,
useCustomizeSources,
type ElementIndexRoute,
type NavItem,
} from '@craftcms/cms/elements';
import NewProductButton, {
type CreatableProductType,
Expand All @@ -14,8 +17,23 @@
creatableProductTypes: CreatableProductType[];
newProductLabel: string;
newProductMenuLabel: string;
sourceNavItems?: NavItem[];
elementType?: string | null;
page?: string | null;
source?: {key?: string | null} | null;
}>();

const subnavActions = useCustomizeSources(() => ({
elementType: props.elementType,
page: props.page,
sourceKey: props.source?.key,
}));

useAppLayout(() => ({
subnav: props.sourceNavItems ?? [],
subnavActions: subnavActions.value,
}));

// `indexUrl` carries the `site` param `Url::cpUrl()` adds, which the index
// query is merged over.
function indexUrlWith(path: string, query = {}): string {
Expand Down
8 changes: 1 addition & 7 deletions src/CatalogPricing/CatalogPricing.php
Original file line number Diff line number Diff line change
Expand Up @@ -301,16 +301,10 @@ public function getCatalogPrices(int $storeId, ?CatalogPricingCondition $conditi

public function getCatalogPricesPageInfo(int $storeId, ?CatalogPricingCondition $conditionBuilder = null, bool $includeBasePrices = true, ?string $searchText = null, int $limit = 100, int $offset = 0): array
{
// getCountForPagination() wraps the query as-is and counts a column from its SELECT —
// but this query only ever selects price/promotionalPrice/salePrice aggregates, never
// purchasableId, so that column was never there to count. select()ing it first (like
// the pre-port Yii2 version did) replaces the aggregate select instead of layering atop
// it, giving a plain "one row per purchasableId" result to just count.
$total = $this->buildCatalogPricesQuery($storeId, $conditionBuilder, $includeBasePrices, $searchText)
->select(['purchasableId'])
->groupBy('purchasableId')
->get()
->count();
->getCountForPagination();

return [
'first' => $offset + 1,
Expand Down
4 changes: 2 additions & 2 deletions src/CatalogPricing/CatalogPricingRules.php
Original file line number Diff line number Diff line change
Expand Up @@ -207,8 +207,8 @@ public function saveCatalogPricingRule(CatalogPricingRule $catalogPricingRule, b
$record->apply = $catalogPricingRule->apply;
$record->applyAmount = $catalogPricingRule->applyAmount;
$record->applyPriceType = $catalogPricingRule->applyPriceType;
$record->dateFrom = Query::prepareDateForDb($catalogPricingRule->dateFrom);
$record->dateTo = Query::prepareDateForDb($catalogPricingRule->dateTo);
$record->setAttribute('dateFrom', Query::prepareDateForDb($catalogPricingRule->dateFrom));
$record->setAttribute('dateTo', Query::prepareDateForDb($catalogPricingRule->dateTo));
$record->description = $catalogPricingRule->description;
$record->enabled = $catalogPricingRule->enabled;
$record->isPromotionalPrice = $catalogPricingRule->isPromotionalPrice;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ public function index(): CpScreenResponse
// slot, so with more than one store, only the first store's table gets one — a single
// combined "New line item status" menu covering every store, rather than one button apiece.
$createMenuItems = $this->readOnly ? [] : $stores->map(fn(Store $store) => [
'label' => $store->name,
'label' => $store->getName(),
'url' => cp_url("commerce/settings/orders/line-item-statuses/{$store->handle}/new"),
])->all();
$createMenuAssigned = false;

$nodes = [];
$stores->each(function(Store $store) use (&$nodes, $isMultiStore, $createMenuItems, &$createMenuAssigned) {
if ($isMultiStore) {
$nodes[] = Heading::make("{$store->handle}-heading", $store->name);
$nodes[] = Heading::make("{$store->handle}-heading", $store->getName());
}

$rows = app(LineItemStatuses::class)->getAllLineItemStatuses($store->id)
Expand Down
4 changes: 2 additions & 2 deletions src/Http/Controllers/Settings/OrderStatusesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ public function index(): CpScreenResponse
// slot, so with more than one store, only the first store's table gets one — a single
// combined "New order status" menu covering every store, rather than one button apiece.
$createMenuItems = $this->readOnly ? [] : $stores->map(fn(Store $store) => [
'label' => $store->name,
'label' => $store->getName(),
'url' => cp_url("commerce/settings/orders/statuses/{$store->handle}/new"),
])->all();
$createMenuAssigned = false;

$nodes = [];
$stores->each(function(Store $store) use (&$nodes, $isMultiStore, $createMenuItems, &$createMenuAssigned) {
if ($isMultiStore) {
$nodes[] = Heading::make("{$store->handle}-heading", $store->name);
$nodes[] = Heading::make("{$store->handle}-heading", $store->getName());
}

$rows = app(OrderStatuses::class)->getAllOrderStatuses($store->id)
Expand Down
2 changes: 1 addition & 1 deletion src/Http/Controllers/Settings/StoresController.php
Original file line number Diff line number Diff line change
Expand Up @@ -514,7 +514,7 @@ public function editSiteStores(): CpScreenResponse
foreach (Sites::getAllSites() as $site) {
$siteStore = $sitesStores->count() > 0 ? $sitesStores->firstWhere('siteId', $site->id) : null;
$siteName = t($site->name, category: 'site');
$storeId = request()->old("siteStores.$site->id.storeId", $siteStore->storeId ?? $primaryStoreId);
$storeId = session()->getOldInput("siteStores.$site->id.storeId", $siteStore->storeId ?? $primaryStoreId);
$values[$site->id] = ['storeId' => $storeId];

$rows[] = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,7 @@ private function initialValues(Discount $discount, Store $store): array
// negative internally (a discount subtracted from the total), shown to the editor as
// a plain positive amount/percentage — flipped back in save().
'perItemDiscount' => $discount->perItemDiscount < 0 ? $discount->perItemDiscount * -1 : $discount->perItemDiscount,
'percentDiscount' => round(-($discount->percentDiscount ?? 0) * 100, 6),
'percentDiscount' => round(-$discount->percentDiscount * 100, 6),
'percentageOffSubject' => $discount->percentageOffSubject,
'ignorePromotions' => $discount->ignorePromotions,
'baseDiscount' => $discount->baseDiscount < 0 ? $discount->baseDiscount * -1 : $discount->baseDiscount,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,14 +46,14 @@ public function index(?string $storeHandle = null): CpScreenResponse
// getName() is just the ISO code today (there's no display-name lookup yet) —
// matches the "Code" column below exactly, which is a pre-existing redundancy,
// not something introduced here.
'name' => $currency->primary
'name' => $currency->getPrimary()
? ['html' => Html::encode(t('{name} (Primary)', ['name' => t($currency->getName(), category: 'site')], category: 'commerce'))]
: ['html' => Html::a(Html::encode(t($currency->getName(), category: 'site')), $currency->getCpEditUrl(), ['class' => 'cell-bold'])],
'handle' => ['html' => FormFields::copytextHtml(['value' => $currency->iso, 'monospace' => true])],
'rate' => $currency->primary
'rate' => $currency->getPrimary()
? ['html' => Html::tag('span', Html::encode(t('Base', category: 'commerce')), ['class' => 'token'])]
: (string) $currency->rate,
'_deletable' => !$currency->primary,
'_deletable' => !$currency->getPrimary(),
])
->values()
->all();
Expand Down Expand Up @@ -102,7 +102,7 @@ public function edit(?string $storeHandle = null, ?int $id = null): CpScreenResp

$currencyOptions = app(Currencies::class)->getAllCurrenciesList();
$hasCompletedOrders = Order::find()->isCompleted(true)->exists();
$isoLocked = $currency->id && $currency->primary && $hasCompletedOrders;
$isoLocked = $currency->id && $currency->getPrimary() && $hasCompletedOrders;

$formatter = app(Formatter::class);
$metaSidebarHtml = $currency->id ? app(ContentHtml::class)->metadataHtml([
Expand Down Expand Up @@ -136,7 +136,7 @@ public function edit(?string $storeHandle = null, ?int $id = null): CpScreenResp
}

$formNodes[] = Field::make(t('Conversion Rate', category: 'commerce'), Number::make('rate')
->mode($currency->primary ? ControlMode::ReadOnly : ControlMode::Editable))
->mode($currency->getPrimary() ? ControlMode::ReadOnly : ControlMode::Editable))
->instructions(t('The conversion rate that will be used when converting an amount to this currency. For example, if an item costs {amount1}, a conversion rate of {rate} would result in {amount2} in the alternate currency.', [
'amount1' => 10,
'rate' => 1.5,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,10 @@
use craft\helpers\Localization;
use CraftCms\Cms\Cp\Html\ContentHtml;
use CraftCms\Cms\Http\Responses\CpScreenResponse;
use CraftCms\Cms\Support\Facades\I18N;
use CraftCms\Cms\Support\Html;
use CraftCms\Cms\Support\Json;
use CraftCms\Cms\Support\Money;
use CraftCms\Cms\Translation\Formatter;
use CraftCms\Cms\Translation\Locale;
use CraftCms\Cms\Ui\Controls\ConditionBuilder;
use CraftCms\Cms\Ui\Controls\Lightswitch;
use CraftCms\Cms\Ui\Controls\Money as MoneyControl;
Expand Down Expand Up @@ -495,9 +493,4 @@ public function delete(Request $request): Response

return $this->asSuccess(t('Shipping rule deleted.', category: 'commerce'));
}

private function percentSymbol(): string
{
return I18N::getFormattingLocale()->getNumberSymbol(Locale::SYMBOL_PERCENT);
}
}
Loading
Loading