/**
  * Returns the html table rows for the article matrix.
  *
  * @param array $data The data we should build the matrix from
  * @param string $resultRows The rendered resulting rows
  * @param int $counter The article counter
  * @param string $headRow The header row for inserting after a number of articles
  * @param array $extraRowData Some additional data like checkbox column
  * @param int $index The level inside the matrix
  * @param array $row The current row data
  *
  * @return void
  */
 protected function getRows(array $data, &$resultRows, &$counter, $headRow, array $extraRowData = array(), $index = 1, array $row = array())
 {
     if (is_array($data)) {
         foreach ($data as $dataItem) {
             $dummyData = $dataItem;
             unset($dummyData['other']);
             $row[$index] = $dummyData;
             if (is_array($dataItem['other'])) {
                 $this->getRows($dataItem['other'], $resultRows, $counter, $headRow, $extraRowData, $index + 1, $row);
             } else {
                 // serialize data for formsaveing
                 $labelData = array();
                 $hashData = array();
                 foreach ($row as $rd) {
                     $hashData[$rd['aUid']] = $rd['vUid'];
                     $labelData[] = $rd['vLabel'];
                 }
                 asort($hashData);
                 // try to fetch an article with this special attribute values
                 $hashData = serialize($hashData);
                 $hash = md5($hashData);
                 if ($this->belib->checkArray($hash, $this->existingArticles, 'attribute_hash')) {
                     continue;
                 }
                 ++$counter;
                 // select format and insert headrow if we are in the 20th row
                 if ($counter % 20 == 0) {
                     $resultRows .= $headRow;
                 }
                 $class = $counter % 2 == 1 ? 'background-color: silver' : 'background: none';
                 // create the row
                 $resultRows .= '<tr><td style="' . $class . '">
                     <input type="checkbox" name="createList[' . $counter . ']" id="createRow_' . $counter . '" />
                     <input type="hidden" name="createData[' . $counter . ']" value="' . htmlspecialchars($hashData) . '" /></td>';
                 $resultRows .= '<td style="' . $class . '">' . implode('</td><td style="' . $class . '">', \CommerceTeam\Commerce\Utility\GeneralUtility::removeXSSStripTagsArray($labelData)) . '</td>';
                 if (!empty($extraRowData)) {
                     $resultRows .= '<td style="' . $class . '">' . implode('</td><td style="' . $class . '">', \CommerceTeam\Commerce\Utility\GeneralUtility::removeXSSStripTagsArray($extraRowData)) . '</td>';
                 }
                 $resultRows .= '</tr>';
             }
         }
     }
 }
示例#2
0
 /**
  * Check attributes of products and categories.
  *
  * @param array $incomingFieldArray Incoming field array
  * @param bool|int $handleAttributes Whether to handle attributes
  *
  * @return mixed
  */
 protected function preProcessAttributes(array $incomingFieldArray, $handleAttributes)
 {
     if ($handleAttributes) {
         // get all parent categories, excluding this
         $this->belib->getParentCategoriesFromList($this->catList);
         $correlationTypes = array();
         // get all correlation types from flexform thats was created by dynaflex!
         if (is_array($incomingFieldArray) && isset($incomingFieldArray['attributes']) && is_array($incomingFieldArray['attributes']) && isset($incomingFieldArray['attributes']['data']) && is_array($incomingFieldArray['attributes']['data']) && isset($incomingFieldArray['attributes']['data']['sDEF']) && is_array($incomingFieldArray['attributes']['data']['sDEF']) && isset($incomingFieldArray['attributes']['data']['sDEF']['lDEF']) && is_array($incomingFieldArray['attributes']['data']['sDEF']['lDEF'])) {
             $correlationTypes = $incomingFieldArray['attributes']['data']['sDEF']['lDEF'];
         }
         $usedAttributes = array();
         foreach ($correlationTypes as $key => $data) {
             $keyData = array();
             // @todo this cant work, we are checking on a new created empty array
             if ($keyData[0] == 'ct') {
                 // get the attributes from the categories of this product
                 $localAttributes = explode(',', $data['vDEF']);
                 if (is_array($localAttributes)) {
                     $validAttributes = array();
                     foreach ($localAttributes as $localAttribute) {
                         if ($localAttribute == '') {
                             continue;
                         }
                         $attributeUid = $this->belib->getUidFromKey($localAttribute, $keyData);
                         if (!$this->belib->checkArray($attributeUid, $usedAttributes, 'uid_foreign')) {
                             $validAttributes[] = $localAttribute;
                             $usedAttributes[] = array('uid_foreign' => $attributeUid);
                         }
                     }
                     $incomingFieldArray['attributes']['data']['sDEF']['lDEF'][$key]['vDEF'] = implode(',', $validAttributes);
                 }
             }
         }
     }
     return $incomingFieldArray;
 }