Skip to content

Commit

Permalink
Merge branch '1.0' into 1.1
Browse files Browse the repository at this point in the history
* 1.0:
  Fix return typehint for TaxonTranslation
  Correct typo
  Add warning about trusted proxies when using stripe behind lb with https
  Fix wrong source currency translation
  [Translations] Updated translations from Crowdin
  Use random_*() instead of rand(), mt_rand() and microtime()
  Make lightbox label translatable (fixes Sylius#9099)
  Fixed Docblock in Taxon document
  • Loading branch information
pamil committed Jan 30, 2018
2 parents d6dc855 + 48c106d commit 0053912
Show file tree
Hide file tree
Showing 18 changed files with 38 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/book/products/taxons.rst
Expand Up @@ -64,7 +64,7 @@ Finally **the parent taxon** has to be added to the system using a repository, a

.. code-block:: php
/** @var TaxonRepositoryInterface $taxonsRepository */
/** @var TaxonRepositoryInterface $taxonRepository */
$taxonRepository = $this->get('sylius.repository.taxon');
$taxonRepository->add($taxon);
Expand Down
4 changes: 4 additions & 0 deletions docs/cookbook/payments/stripe.rst
Expand Up @@ -30,6 +30,10 @@ Go to the ``http://localhost:8000/admin/payment-methods/new/stripe_checkout`` ur

If your are not sure how to do it check how we do it :doc:`for Paypal in this cookbook </cookbook/payments/paypal>`.

.. warning::

When your project is behind a loadbalancer and uses https you probably need to configure `trusted proxies <http://symfony.com/doc/current/deployment/proxies.html>`_. Otherwise the payment will not succeed and the user will endlessly loopback to the payment page without any notice.

Choosing Stripe Credit Card method in Checkout
----------------------------------------------

Expand Down
12 changes: 6 additions & 6 deletions src/Sylius/Behat/Context/Setup/OrderContext.php
Expand Up @@ -485,9 +485,9 @@ public function customersHaveAddedProductsToTheCartForTotalOf($numberOfCustomers
$total = $this->getPriceFromString($total);

for ($i = 0; $i < $numberOfCustomers; ++$i) {
$order = $this->createCart($customers[rand(0, $numberOfCustomers - 1)]);
$order = $this->createCart($customers[random_int(0, $numberOfCustomers - 1)]);

$price = $i === ($numberOfCustomers - 1) ? $total : rand(1, $total);
$price = $i === ($numberOfCustomers - 1) ? $total : random_int(1, $total);
$total -= $price;

$this->addVariantWithPriceToOrder($order, $sampleProductVariant, $price);
Expand Down Expand Up @@ -873,11 +873,11 @@ private function createOrders(
$total = $this->getPriceFromString($total);

for ($i = 0; $i < $numberOfOrders; ++$i) {
$order = $this->createOrder($customers[rand(0, $numberOfCustomers - 1)], '#' . uniqid());
$order = $this->createOrder($customers[random_int(0, $numberOfCustomers - 1)], '#' . uniqid());
$order->setState(OrderInterface::STATE_NEW); // Temporary, we should use checkout to place these orders.
$this->applyPaymentTransitionOnOrder($order, PaymentTransitions::TRANSITION_COMPLETE);

$price = $i === ($numberOfOrders - 1) ? $total : rand(1, $total);
$price = $i === ($numberOfOrders - 1) ? $total : random_int(1, $total);
$total -= $price;

$this->addVariantWithPriceToOrder($order, $sampleProductVariant, $price);
Expand Down Expand Up @@ -912,11 +912,11 @@ private function createOrdersWithProduct(
$total = $this->getPriceFromString($total);

for ($i = 0; $i < $numberOfOrders; ++$i) {
$order = $this->createOrder($customers[rand(0, $numberOfCustomers - 1)], '#' . uniqid(), $product->getChannels()->first());
$order = $this->createOrder($customers[random_int(0, $numberOfCustomers - 1)], '#' . uniqid(), $product->getChannels()->first());
$order->setState(OrderInterface::STATE_NEW);
$this->applyPaymentTransitionOnOrder($order, PaymentTransitions::TRANSITION_COMPLETE);

$price = $i === ($numberOfOrders - 1) ? $total : rand(1, $total);
$price = $i === ($numberOfOrders - 1) ? $total : random_int(1, $total);
$total -= $price;

$this->addVariantWithPriceToOrder($order, $sampleProductVariant, $price);
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Behat/Context/Setup/ProductAttributeContext.php
Expand Up @@ -277,7 +277,7 @@ public function thisProductHasPercentAttributeWithValueAtPosition(
) {
$attribute = $this->provideProductAttribute('percent', $productAttributeName);
$attribute->setPosition((int) $position);
$attributeValue = $this->createProductAttributeValue(rand(1, 100) / 100, $attribute);
$attributeValue = $this->createProductAttributeValue(random_int(1, 100) / 100, $attribute);

$product->addAttribute($attributeValue);

Expand Down
Expand Up @@ -14,7 +14,7 @@ sylius_grid:
sortable: ~
sourceCurrency:
type: twig
label: sylius.ui.base_currency
label: sylius.ui.source_currency
path: .
options:
template: "@SyliusAdmin/ExchangeRate/Grid/Field/sourceCurrencyName.html.twig"
Expand Down
Expand Up @@ -85,10 +85,10 @@ protected function configureOptions(OptionsResolver $resolver): void
return $this->faker->lastName;
})
->setDefault('phone_number', function (Options $options): ?string {
return mt_rand(1, 100) > 50 ? $this->faker->phoneNumber : null;
return random_int(1, 100) > 50 ? $this->faker->phoneNumber : null;
})
->setDefault('company', function (Options $options): ?string {
return mt_rand(1, 100) > 50 ? $this->faker->company : null;
return random_int(1, 100) > 50 ? $this->faker->company : null;
})
->setDefault('street', function (Options $options): string {
return $this->faker->streetAddress;
Expand Down
Expand Up @@ -130,7 +130,7 @@ private function getRandomStatus(): string
{
$statuses = [ReviewInterface::STATUS_NEW, ReviewInterface::STATUS_ACCEPTED, ReviewInterface::STATUS_REJECTED];

return $statuses[(rand(0, 2))];
return $statuses[random_int(0, 2)];
}

/**
Expand Down
Expand Up @@ -65,7 +65,7 @@ public static function randomOne(RepositoryInterface $repository): \Closure
public static function randomOneOrNull(RepositoryInterface $repository, int $chanceOfRandomOne): \Closure
{
return function (Options $options) use ($repository, $chanceOfRandomOne) {
if (mt_rand(1, 100) > $chanceOfRandomOne) {
if (random_int(1, 100) > $chanceOfRandomOne) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Sylius/Bundle/CoreBundle/Fixture/OrderFixture.php
Expand Up @@ -220,7 +220,7 @@ protected function configureOptionsNode(ArrayNodeDefinition $optionsNode): void
*/
private function generateItems(OrderInterface $order): void
{
$numberOfItems = rand(1, 5);
$numberOfItems = random_int(1, 5);
$products = $this->productRepository->findAll();

for ($i = 0; $i < $numberOfItems; ++$i) {
Expand All @@ -230,7 +230,7 @@ private function generateItems(OrderInterface $order): void
$variant = $this->faker->randomElement($product->getVariants()->toArray());

$item->setVariant($variant);
$this->orderItemQuantityModifier->modify($item, rand(1, 5));
$this->orderItemQuantityModifier->modify($item, random_int(1, 5));

$order->addItem($item);
}
Expand Down
Expand Up @@ -155,7 +155,7 @@ public function load(array $options): void
'taxons' => ['t_shirts', $categoryTaxonCode],
'product_attributes' => [
't_shirt_brand' => $this->faker->randomElement(['Nike', 'Adidas', 'JKM-476 Streetwear', 'Potato', 'Centipede Wear']),
't_shirt_collection' => sprintf('Sylius %s %s', $this->faker->randomElement(['Summer', 'Winter', 'Spring', 'Autumn']), mt_rand(1995, 2012)),
't_shirt_collection' => sprintf('Sylius %s %s', $this->faker->randomElement(['Summer', 'Winter', 'Spring', 'Autumn']), random_int(1995, 2012)),
't_shirt_material' => $this->faker->randomElement(['Centipede', 'Wool', 'Centipede 10% / Wool 90%', 'Potato 100%']),
],
'product_options' => ['t_shirt_color', 't_shirt_size'],
Expand Down
Expand Up @@ -2,6 +2,8 @@
# (c) Paweł Jędrzejewski

sylius:
lightbox:
image_album_label: 'Image %1 of %2'
menu:
shop:
account:
Expand Down
Expand Up @@ -58,3 +58,13 @@

{% include '@SyliusShop/Product/Show/_associations.html.twig' %}
{% endblock %}

{% block javascripts %}
{{ parent() }}

<script type="text/javascript">
lightbox.option({
'albumLabel': '{{ 'sylius.lightbox.image_album_label'|trans|escape('js') }}'
});
</script>
{% endblock %}
Expand Up @@ -677,7 +677,7 @@ sylius:
start_date: 'Datum zahájení'
starts_at: 'Začíná'
starts_with: 'Začíná na'
state: 'Stát'
state: 'Stav'
status: 'Status'
street: 'Ulice'
string_blocks: 'Řetězcové bloky'
Expand Down
Expand Up @@ -23,6 +23,6 @@ final class RandomInvoiceNumberGenerator implements InvoiceNumberGeneratorInterf
*/
public function generate(OrderInterface $order, PaymentInterface $payment): string
{
return mt_rand(1, 100000) . '-' . mt_rand(1, 100000);
return random_int(1, 100000) . '-' . random_int(1, 100000);
}
}
2 changes: 1 addition & 1 deletion src/Sylius/Component/Core/Uploader/ImageUploader.php
Expand Up @@ -45,7 +45,7 @@ public function upload(ImageInterface $image): void
}

do {
$hash = md5(uniqid((string) mt_rand(), true));
$hash = bin2hex(random_bytes(16));
$path = $this->expandPath($hash . '.' . $image->getFile()->guessExtension());
} while ($this->filesystem->has($path));

Expand Down
Expand Up @@ -99,7 +99,7 @@ private function generateUniqueCode(int $codeLength, array $generatedCoupons): s
Assert::nullOrRange($codeLength, 1, 40, 'Invalid %d code length should be between %d and %d');

do {
$hash = sha1((string) microtime(true));
$hash = bin2hex(random_bytes(20));
$code = strtoupper(substr($hash, 0, $codeLength));
} while ($this->isUsedCode($code, $generatedCoupons));

Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Component/Taxonomy/Model/Taxon.php
Expand Up @@ -336,7 +336,7 @@ public function getTranslation(?string $locale = null): TranslationInterface
/**
* {@inheritdoc}
*/
protected function createTranslation(): TaxonTranslation
protected function createTranslation(): TaxonTranslationInterface
{
return new TaxonTranslation();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Sylius/Component/User/Model/User.php
Expand Up @@ -128,7 +128,7 @@ class User implements UserInterface

public function __construct()
{
$this->salt = base_convert(sha1(uniqid((string) mt_rand(), true)), 16, 36);
$this->salt = base_convert(bin2hex(random_bytes(20)), 16, 36);
$this->oauthAccounts = new ArrayCollection();
$this->createdAt = new \DateTime();

Expand Down

0 comments on commit 0053912

Please sign in to comment.