Ejemplo n.º 1
0
 /**
  * Add simple product to our configurable product
  *
  * @param Simple $product
  * @param bool $visibleInFrontend
  * @param bool $searchable
  *
  * @return $this
  * @throws \Datapump\Exception\ProductSkuAlreadyAdded
  * @throws \Datapump\Exception\SimpleProductMissingConfigurableAttribute
  */
 public function addSimpleProduct(Simple $product, $visibleInFrontend = false, $searchable = false)
 {
     $product->check();
     if (!$this->simpleProductConfigAttributeTest($product)) {
         throw new Exception\SimpleProductMissingConfigurableAttribute(sprintf('%s is missing the keys %s', $product->getRequiredData()->getSku(), implode(', ', $this->getRequiredData()->get(self::CONFIG_ATTR_KEY))));
     }
     foreach ($this->simpleProducts as $p) {
         /** @var Simple $p */
         if ($p->get('sku') === $product->get('sku')) {
             throw new Exception\ProductSkuAlreadyAdded(sprintf('Product with SKU: %s is already added', $product->get('sku')));
         }
     }
     $product->getRequiredData()->setVisibility($visibleInFrontend, $searchable);
     $this->simpleProducts[] = $product;
     return $this;
 }