/** * {@inheritdoc} */ public function getMapping() { $magentoAttributeMappings = $this->attributeMappingManager->getAllMagentoAttribute($this->clientParameters->getSoapUrl()); $attributeCodeMapping = $this->attributeCodeMappingMerger->getMapping(); $mappingCollection = new MappingCollection(); foreach ($magentoAttributeMappings as $magentoAttributeMapping) { $pimAttributeCode = $magentoAttributeMapping->getAttribute()->getCode(); $mappingCollection->add(['source' => $attributeCodeMapping->getTarget($pimAttributeCode), 'target' => $magentoAttributeMapping->getMagentoAttributeId(), 'deletable' => true]); } return $mappingCollection; }
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); }
/** * Handle attribute creation and update. * * @param array $attribute * @param AbstractAttribute $pimAttribute * * @throws InvalidItemException */ protected function handleAttribute(array $attribute, $pimAttribute) { if (count($attribute) === self::ATTRIBUTE_UPDATE_SIZE) { $this->webservice->updateAttribute($attribute); $magentoAttributeId = $this->attributeIdMappingMerger->getMapping()->getTarget($pimAttribute->getCode()); $this->manageAttributeSet($magentoAttributeId, $pimAttribute); $this->stepExecution->incrementSummaryInfo('attribute_updated'); } else { $magentoAttributeId = $this->webservice->createAttribute($attribute); $this->manageAttributeSet($magentoAttributeId, $pimAttribute); $this->stepExecution->incrementSummaryInfo('attribute_created'); $magentoUrl = $this->getSoapUrl(); $this->attributeMappingManager->registerAttributeMapping($pimAttribute, $magentoAttributeId, $magentoUrl); } }
function it_returns_a_mapping_collection_on_get_mapping(AttributeMappingManager $attributeMappingManager) { $attributeMappingManager->getAllMagentoAttribute('http://test.dev/api')->willReturn([]); $this->getMapping()->shouldReturnAnInstanceOf('Pim\\Bundle\\ConnectorMappingBundle\\Mapper\\MappingCollection'); }