コード例 #1
0
 public function updateAttributeSet(Product $product)
 {
     $attributes = $product->getCategory()->getAttributes();
     $attributesCloned = clone $attributes;
     $attrValues = $product->getAttributeValues();
     if ($attrValues->count() > 0) {
         $em = $this->doctrine->getManager();
         foreach ($attrValues as $attrValue) {
             $attribute = $attrValue->getAttribute();
             if ($attributes->contains($attribute)) {
                 $attributesCloned->removeElement($attribute);
             } else {
                 $product->removeAttributeValue($attrValue);
                 $em->remove($attrValue);
             }
         }
         $em->flush();
     }
     if ($attributesCloned->count() > 0) {
         foreach ($attributesCloned as $attribute) {
             $attrValue = new AttributeValue();
             $attrValue->setProduct($product)->setAttribute($attribute);
             $product->addAttributeValue($attrValue);
         }
     }
     return $product;
 }
コード例 #2
0
 /**
  * {@inheritDoc}
  */
 public function getCategory()
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'getCategory', array());
     return parent::getCategory();
 }