Advertisement
Guest User

Untitled

a guest
Jul 28th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.36 KB | None | 0 0
  1. $this->attribute->loadByCode(4, 'deal_options');
  2.  
  3. // Load Configurable Product
  4. $product = $this->product->create();
  5. $product = $product->load($parentId);
  6. $product->setStockData(['use_config_manage_stock' => 1, 'is_in_stock' => 1]);
  7.  
  8. $attributeValues = [];
  9. $options = $this->attribute->getOptions();
  10. array_shift($options); //remove the first option which is empty
  11. foreach($options as $option) {
  12. $attributeValues[] = [
  13. 'label' => 'Option',
  14. 'attribute_id' => $this->attribute->getId(),
  15. 'value_index' => $option->getValue(),
  16. ];
  17. }
  18.  
  19. $configurableAttributesData = [
  20. [
  21. 'attribute_id' => $this->attribute->getId(),
  22. 'code' => $this->attribute->getAttributeCode(),
  23. 'label' => $this->attribute->getStoreLabel(),
  24. 'position' => '1',
  25. 'values' => $attributeValues,
  26. ],
  27. ];
  28.  
  29. $configurableOptions = $this->optionsFactory->create($configurableAttributesData);
  30.  
  31. $extensionConfigurableAttributes = $product->getExtensionAttributes();
  32. $extensionConfigurableAttributes->setConfigurableProductOptions($configurableOptions);
  33. $extensionConfigurableAttributes->setConfigurableProductLinks($simpleDeals['ids']);
  34. $product->setExtensionAttributes($extensionConfigurableAttributes);
  35.  
  36. $this->productRepository->save($product);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement