View more context

 

wmk

Hi all, https://github.com/silvershop/silvershop-core/blob/master/src/ORM/FieldType/ShopCurrency.php lacks proper casting for negative values. When I do a PR, is it enough to cast "Nice", or do I also need to cast all methods that can return Nice(), like NiceOrEmpty?

Show 1 attachment(s)
src/ORM/FieldType/ShopCurrency.php

<?php

namespace SilverShop\ORM\FieldType;

use SilverStripe\ORM\FieldType\DBCurrency;

/**
 * Improvements to Currency for presenting in templates.
 *
 * @package shop
 */
class ShopCurrency extends DBCurrency
{
    /**
     * The shop currency decimal delimiter
     *
     * @config
     * @var    string
     */
    private static $decimal_delimiter = '.';

    /**
     * The shop currency thousands delimiter
     *
     * @config
     * @var    string
     */
    private static $thousand_delimiter = ',';

    /**
     * Whether or not to append the currency symbol to
     *
     * @config
     * @var    string
     */
    private static $append_symbol = false;

    /**
     * HTML to use for negative numbers
     *
     * @config
     * @var    string
     */
    private static $negative_value_format = '<span class="negative">(%s)</span>';

    public function Nice()
    {
        $symbol = $this->config()->currency_symbol;
        $val = number_format(
            abs($this->value),
            2,
            self::config()->decimal_delimiter,
            self::config()->thousand_delimiter
        );
        if ($this->config()->append_symbol) {
            $val = $val . ' ' . $symbol;
        } else {
            $val = $symbol . $val;
        }
        if ($this->value < 0) {
            return sprintf(self::config()->negative_value_format, $val);
        }

        return $val;
    }

    public function forTemplate()
    {
        return $this->Nice();
    }

    /**
     * If no cents on the price, trim those off.
     *
     * @return string
     */
    public function TrimCents()
    {
        $val = $this->value;

        if (floor($val) == $val) {
            return floor($val);
        }

        return $val;
    }

    public function NiceOrEmpty()
    {
        if ($this->value != 0) {
            return $this->Nice();
        }
        return '';
    }
}
Hide attachment content
wmk

I'm currently updating a SilverShop to SS4. Due to file versioning and old content OrderItem doesn't show the latest Image, as the Product was published some time ago and the Images got versioned recently during the update to SS4. Anyone has an idea how to fix this?

wmk

Seems I need to update the file version table...

wmk

well, just trying to figure that out per SQL... is tricky, when one image is used by more products...

wmk

I tend to keep it simple and just set files "last edited" to created...