/** * Handle deletion of families that are not in PIM anymore * * @param string $name * @param int $id */ protected function handleFamilyNotInPimAnymore($name, $id) { if (!$this->familyMappingManager->magentoFamilyExists($id, $this->getSoapUrl()) && !in_array($name, $this->getIgnoredFamilies())) { $this->webservice->removeAttributeSet($id); $this->stepExecution->incrementSummaryInfo(self::FAMILY_DELETED); } }
function it_increments_summary_info_with_family_exists_if_it_exists($webservice, $stepExecution, Family $family, FamilyMappingManager $familyMappingManager) { $batches = [['families_to_create' => ['attributeSetName' => 'family_code'], 'family_object' => $family]]; $webservice->createAttributeSet('family_code')->willThrow('\\Pim\\Bundle\\MagentoConnectorBundle\\Webservice\\SoapCallException'); $familyMappingManager->registerFamilyMapping(Argument::cetera())->shouldNotBeCalled(); $stepExecution->incrementSummaryInfo('family_exists')->shouldBeCalled(); $this->write($batches); }
/** * Handle family creation. * * @param array $item * * @throws InvalidItemException */ protected function handleNewFamily(array $item) { if (isset($item['families_to_create'])) { $pimFamily = $item['family_object']; $magentoFamilyId = $this->webservice->createAttributeSet($item['families_to_create']['attributeSetName']); $magentoUrl = $this->getSoapUrl(); $this->familyMappingManager->registerFamilyMapping($pimFamily, $magentoFamilyId, $magentoUrl); $this->stepExecution->incrementSummaryInfo('family_created'); } }
/** * Handle deletion of families that are not in PIM anymore. * * @param string $name * @param int $id * * @throws InvalidItemException */ protected function handleFamilyNotInPimAnymore($name, $id) { if ($this->notInPimAnymoreAction === self::DELETE && !$this->familyMappingManager->magentoFamilyExists($id, $this->getSoapUrl()) && !in_array($name, $this->getIgnoredFamilies())) { try { $this->webservice->removeAttributeSet($id, $this->forceAttributeSetRemoval); $this->stepExecution->incrementSummaryInfo('family_deleted'); } catch (SoapCallException $e) { throw new InvalidItemException($e->getMessage(), [$id], [$e]); } } }
/** * Get all sources * @param Family $family * * @return array */ public function getAllSources(Family $family = null) { $sources = []; if ($this->isValid()) { $families = $this->familyManager->getFamilies(); foreach ($families as $family) { $sources[] = ['id' => $family->getCode(), 'name' => $family->getCode()]; } } return $sources; }
/** * Create a group in an attribute set. * * @param AbstractAttribute $pimAttribute * * @throws SoapCallException */ protected function addGroupToAttributeSet(AbstractAttribute $pimAttribute) { $families = $pimAttribute->getFamilies(); $group = $pimAttribute->getGroup(); if (isset($group)) { $groupName = $group->getCode(); foreach ($families as $family) { $familyMagentoId = $this->familyMappingManager->getIdFromFamily($family, $this->getSoapUrl()); if (null === $familyMagentoId) { $magentoAttributeSets = $this->webservice->getAttributeSetList(); if (array_key_exists($family->getCode(), $magentoAttributeSets)) { $familyMagentoId = $magentoAttributeSets[$family->getCode()]; } } try { $magentoGroupId = $this->webservice->addAttributeGroupToAttributeSet($familyMagentoId, $groupName); $this->attributeGroupMappingManager->registerGroupMapping($group, $family, $magentoGroupId, $this->getSoapUrl()); } catch (SoapCallException $e) { if (static::SOAP_FAULT_GROUP_ALREADY_IN_SET === $e->getPrevious()->faultcode) { echo "DEBUG: Group " . $groupName . " already exists in attribute set " . $familyMagentoId . "\n"; } else { throw $e; } } } } }
/** * Create a group in an attribute set * * @param AbstractAttribute $pimAttribute * * @throws \Exception * @throws \SoapCallException * * @return void */ protected function addGroupToAttributeSet($pimAttribute) { $families = $pimAttribute->getFamilies(); $group = $pimAttribute->getGroup(); if (isset($group)) { $groupName = $group->getCode(); foreach ($families as $family) { $familyMagentoId = $this->familyMappingManager->getIdFromFamily($family, $this->getSoapUrl()); if (null === $familyMagentoId) { $magentoAttributeSets = $this->webservice->getAttributeSetList(); if (array_key_exists($family->getCode(), $magentoAttributeSets)) { $familyMagentoId = $magentoAttributeSets[$family->getCode()]; } } try { $magentoGroupId = $this->webservice->addAttributeGroupToAttributeSet($familyMagentoId, $groupName); $this->attributeGroupMappingManager->registerGroupMapping($group, $family, $magentoGroupId, $this->getSoapUrl()); } catch (SoapCallException $e) { if (!strpos($e->getMessage(), 'already') !== false) { throw $e; } } } } }
function it_sends_attribute_with_group_and_family_to_create_on_magento_webservice($webservice, AbstractAttribute $attribute, AttributeMappingManager $attributeMappingManager, AttributeGroupMappingManager $attributeGroupMappingManager, FamilyMappingManager $familyMappingManager, AttributeGroup $group, Family $family, $magentoMappingMerger, MappingCollection $mapping) { $attributes = [[$attribute, ['create' => ['attributeName' => 'attribute_code']]]]; $this->setMagentoUrl(null); $this->setWsdlUrl('/api/soap/?wsdl'); $attribute->getCode()->willReturn('attributeName'); $attribute->getFamilies()->willReturn([$family]); $attribute->getGroup()->willReturn($group); $magentoMappingMerger->getMapping()->willReturn($mapping); $mapping->getTarget($attribute)->willReturn(12); $mapping->getSource(12)->willReturn(12); $group->getCode()->willReturn('group_name'); $familyMappingManager->getIdFromFamily(Argument::any(), '/api/soap/?wsdl')->willReturn(414); $webservice->addAttributeGroupToAttributeSet(414, 'group_name')->shouldBeCalled()->willReturn(797); $webservice->createAttribute(Argument::any())->willReturn(12); $webservice->addAttributeToAttributeSet(12, 414, 797)->shouldBeCalled(); $attributeGroupMappingManager->registerGroupMapping($group, $family, 797, '/api/soap/?wsdl')->shouldBeCalled(); $attributeGroupMappingManager->getIdFromGroup($group, $family, '/api/soap/?wsdl')->willReturn(797); $attributeMappingManager->registerAttributeMapping($attribute, 12, '/api/soap/?wsdl')->shouldBeCalled(); $this->write($attributes); }