コード例 #1
0
ファイル: Helper.php プロジェクト: GerDner/luck-docker
 private function insertConfiguratorData($groups)
 {
     $pos = 1;
     $data = array();
     foreach ($groups as $groupName => $options) {
         $group = new Models\Article\Configurator\Group();
         $group->setName($groupName);
         $group->setPosition($groups);
         $this->db->executeQuery("DELETE FROM s_article_configurator_groups WHERE name = ?", array($groupName));
         $collection = array();
         $optionPos = 1;
         foreach ($options as $optionName) {
             $this->db->executeQuery("DELETE FROM s_article_configurator_options WHERE name = ?", array($optionName));
             $option = new Models\Article\Configurator\Option();
             $option->setName($optionName);
             $option->setPosition($optionPos);
             $collection[] = $option;
             $optionPos++;
         }
         $group->setOptions($collection);
         $pos++;
         $data[] = $group;
         $this->entityManager->persist($group);
         $this->entityManager->flush();
         $this->entityManager->clear();
         $this->createdConfiguratorGroups[] = $group->getId();
     }
     return $data;
 }
コード例 #2
0
ファイル: Variant.php プロジェクト: ClaudioThomas/shopware-4
 /**
  * Resolves the passed configuratorOptions parameter for a single variant.
  * Each passed configurator option, has to be configured in the article configurator set.
  *
  * @param array $data
  * @param ArticleModel $article
  * @param Detail $variant
  * @return \Doctrine\Common\Collections\Collection
  * @throws \Shopware\Components\Api\Exception\CustomValidationException
  */
 protected function prepareConfigurator(array $data, ArticleModel $article, Detail $variant)
 {
     if (!$article->getConfiguratorSet()) {
         throw new ApiException\CustomValidationException('A configurator set has to be defined');
     }
     $availableGroups = $article->getConfiguratorSet()->getGroups();
     $options = new ArrayCollection();
     foreach ($data['configuratorOptions'] as $optionData) {
         $availableGroup = $this->getAvailableGroup($availableGroups, array('id' => $optionData['groupId'], 'name' => $optionData['group']));
         //group is in the article configurator set configured?
         if (!$availableGroup) {
             continue;
         }
         //check if the option is available in the configured article configurator set.
         $option = $this->getAvailableOption($availableGroup->getOptions(), array('id' => $optionData['optionId'], 'name' => $optionData['option']));
         if (!$option) {
             if (!$optionData['option']) {
                 throw new ApiException\CustomValidationException('A new configurator option requires a name');
             }
             $option = new Option();
             $option->setPosition(0);
             $option->setName($optionData['option']);
             $option->setGroup($availableGroup);
             $this->getManager()->persist($option);
         }
         $options->add($option);
     }
     $data['configuratorOptions'] = $options;
     $variant->setConfiguratorOptions($options);
     return $data;
 }