Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-9147: Symbol attribute type described in Developer Documentation #2525

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

julitafalcondusza
Copy link
Contributor

@julitafalcondusza julitafalcondusza commented Oct 24, 2024

Question Answer
JIRA Ticket (https://issues.ibexa.co/browse/IBX-9147)
Versions 4.6+

Symbol attribute type described in Developer Documentation

Preview:

Checklist

  • Text renders correctly
  • Text has been checked with vale
  • Description metadata is up to date
  • Redirects cover removed/moved pages
  • Code samples are working
  • PHP code samples have been fixed with PHP CS fixer
  • Added link to this PR in relevant JIRA ticket or code PR

Copy link
Contributor

@mnocon mnocon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for preparing this!

I've left a couple of suggestions to make it clearer - but I believe it already includes all the neccessary parts, we just need to improve them a bit.

I cannot provide you with the PostgreSQL schema, we will need someone from the backend team for that.

docs/pim/symbol_attribute_type.md Outdated Show resolved Hide resolved
docs/pim/symbol_attribute_type.md Outdated Show resolved Hide resolved
docs/pim/symbol_attribute_type.md Outdated Show resolved Hide resolved
docs/pim/symbol_attribute_type.md Outdated Show resolved Hide resolved
docs/pim/symbol_attribute_type.md Outdated Show resolved Hide resolved
docs/pim/symbol_attribute_type.md Show resolved Hide resolved
docs/pim/symbol_attribute_type.md Outdated Show resolved Hide resolved
@adamwojs
Copy link
Member

I cannot provide you with the PostgreSQL schema, we will need someone from the backend team for that.

I will take care of it.

Copy link

code_samples/ change report

Before (on target branch)After (in current PR)

code_samples/pim/Symbol/Format/Checksum/LuhnChecksum.php


code_samples/pim/Symbol/Format/Checksum/LuhnChecksum.php

docs/pim/symbol_attribute_type.md@119:``` php
docs/pim/symbol_attribute_type.md@120:[[= include_file('code_samples/pim/Symbol/Format/Checksum/LuhnChecksum.php') =]]
docs/pim/symbol_attribute_type.md@121:```

001⫶
002⫶
003⫶declare(strict_types=1);
004⫶
005⫶namespace App\PIM\Symbol\Format\Checksum;
006⫶
007⫶use Ibexa\Contracts\ProductCatalog\Values\AttributeDefinitionInterface;
008⫶use Ibexa\Contracts\ProductCatalogSymbolAttribute\Value\ChecksumInterface;
009⫶
010⫶final class LuhnChecksum implements ChecksumInterface
011⫶{
012⫶ public function validate(AttributeDefinitionInterface $attributeDefinition, string $value): bool
013⫶ {
014⫶ $digits = $this->getDigits($value);
015⫶
016⫶ $count = count($digits);
017⫶ $total = 0;
018⫶ for ($i = $count - 2; $i >= 0; $i -= 2) {
019⫶ $digit = $digits[$i];
020⫶ if ($i % 2 === 0) {
021⫶ $digit *= 2;
022⫶ }
023⫶
024⫶ $total += $digit > 9 ? $digit - 9 : $digit;
025⫶ }
026⫶
027⫶ $checksum = $digits[$count - 1];
028⫶
029⫶ return $total + $checksum === 0;
030⫶ }
031⫶
032⫶ /**
033⫶ * Returns an array of digits from the given value (skipping any formatting characters).
034⫶ *
035⫶ * @return int[]
036⫶ */
037⫶ private function getDigits(string $value): array
038⫶ {
039⫶ $chars = array_filter(
040⫶ str_split($value),
041⫶ static fn (string $char): bool => $char !== '-'
042⫶ );
043⫶
044⫶ return array_map('intval', array_values($chars));
045⫶ }
046⫶}

Download colorized diff

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants