Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Issn.php
Go to the documentation of this file.
1 <?php
25 #require_once 'Zend/Validate/Barcode/AdapterAbstract.php';
26 
34 {
39  protected $_length = array(8, 13);
40 
45  protected $_characters = '0123456789X';
46 
51  protected $_checksum = '_gtin';
52 
59  public function checkChars($value)
60  {
61  if (strlen($value) != 8) {
62  if (strpos($value, 'X') !== false) {
63  return false;
64  }
65  }
66 
67  return parent::checkChars($value);
68  }
69 
76  public function checksum($value)
77  {
78  if (strlen($value) == 8) {
79  $this->_checksum = '_issn';
80  } else {
81  $this->_checksum = '_gtin';
82  }
83 
84  return parent::checksum($value);
85  }
86 
94  protected function _issn($value)
95  {
96  $checksum = substr($value, -1, 1);
97  $values = str_split(substr($value, 0, -1));
98  $check = 0;
99  $multi = 8;
100  foreach($values as $token) {
101  if ($token == 'X') {
102  $token = 10;
103  }
104 
105  $check += ($token * $multi);
106  --$multi;
107  }
108 
109  $check %= 11;
110  $check = 11 - $check;
111  if ($check == $checksum) {
112  return true;
113  } else if (($check == 10) && ($checksum == 'X')) {
114  return true;
115  }
116 
117  return false;
118  }
119 }
$values
Definition: options.phtml:88
$value
Definition: gender.phtml:16