Beispiel #1
0
 public function save(EntityInterface $object)
 {
     // TODO: Do we want to save variations via update button?
     if ($object instanceof Product\Variable) {
         $wpdb = $this->wp->getWPDB();
         $this->removeAllVariationsExcept($object->getId(), array_map(function ($item) {
             /** @var Product\Variable\Variation $item */
             return $item->getId();
         }, $object->getVariations()));
         foreach ($object->getVariations() as $variation) {
             /** @var Product\Variable\Variation $variation */
             if ($variation->getProduct() === null) {
                 $variation->setProduct($this->_createVariableProduct($variation, $object));
                 $variation->setId($variation->getProduct()->getId());
             }
             $this->productService->save($variation->getProduct());
             foreach ($variation->getAttributes() as $attribute) {
                 /** @var Product\Variable\Attribute $attribute */
                 $data = array('variation_id' => $variation->getId(), 'attribute_id' => $attribute->getAttribute()->getId(), 'value' => $attribute->getValue());
                 if ($attribute->exists()) {
                     $wpdb->update($wpdb->prefix . 'jigoshop_product_variation_attribute', $data, array('variation_id' => $variation->getId(), 'attribute_id' => $attribute->getAttribute()->getId()));
                 } else {
                     $wpdb->insert($wpdb->prefix . 'jigoshop_product_variation_attribute', $data);
                     $attribute->setExists(Product\Variable\Attribute::VARIATION_ATTRIBUTE_EXISTS);
                 }
             }
         }
     }
 }
Beispiel #2
0
 /**
  * Saves entity to database.
  *
  * @param $object EntityInterface Entity to save.
  */
 public function save(EntityInterface $object)
 {
     if (!$object instanceof Entity) {
         throw new Exception('Trying to save not a coupon!');
     }
     // TODO: Support for transactions!
     $fields = $object->getStateToSave();
     if (isset($fields['id']) || isset($fields['title']) || isset($fields['code'])) {
         // We do not need to save ID, title and code (post name) as they are saved by WordPress itself.
         unset($fields['id'], $fields['title'], $fields['code']);
     }
     foreach ($fields as $field => $value) {
         $this->wp->updatePostMeta($object->getId(), $field, $value);
     }
     $this->wp->doAction('jigoshop\\service\\coupon\\save', $object);
 }
Beispiel #3
0
 /**
  * Saves product to database.
  *
  * @param EntityInterface $object Customer to save.
  *
  * @throws Exception
  */
 public function save(EntityInterface $object)
 {
     if (!$object instanceof Entity) {
         throw new Exception('Trying to save not a customer!');
     }
     $fields = $object->getStateToSave();
     if (isset($fields['id']) || isset($fields['name']) || isset($fields['email']) || isset($fields['login'])) {
         // TODO: Do we want to update user data like this?
         //			$this->wp->wpUpdateUser(array(
         //				'ID' => $fields['id'],
         //				'display_name' => $fields['name'],
         //				'user_email' => $fields['email'],
         //			));
         unset($fields['id'], $fields['name'], $fields['email'], $fields['login']);
     }
     if ($object instanceof Entity\Guest) {
         $this->session->setField(Factory::CUSTOMER, $fields);
         return;
     }
     foreach ($fields as $field => $value) {
         $this->wp->updateUserMeta($object->getId(), $field, $value);
     }
 }
Beispiel #4
0
 /**
  * Saves product to database.
  *
  * @param EntityInterface $object Customer to save.
  * @throws Exception
  */
 public function save(EntityInterface $object)
 {
     $this->customers[$object->getId()] = $object;
     $this->service->save($object);
 }
Beispiel #5
0
 /**
  * Saves entity to database.
  *
  * @param $object EntityInterface Entity to save.
  */
 public function save(EntityInterface $object)
 {
     $this->queries = array();
     $this->objects[$object->getId()] = $object;
     $this->service->save($object);
 }
Beispiel #6
0
 /**
  * Saves entity to database.
  *
  * @param $object EntityInterface Entity to save.
  */
 public function save(EntityInterface $object)
 {
     $this->queries = array();
     $this->objects[$object->getId()] = $object;
     unset($this->thumbnails[$object->getId()]);
     unset($this->productAttributes[$object->getId()]);
     $this->service->save($object);
 }
Beispiel #7
0
 /**
  * Saves entity to database.
  *
  * @param $object EntityInterface Entity to save.
  */
 public function save(EntityInterface $object)
 {
     if (!$object instanceof \Jigoshop\Entity\Email) {
         throw new Exception('Trying to save not an email!');
     }
     // TODO: Support for transactions!
     $fields = $object->getStateToSave();
     if (isset($fields['id']) || isset($fields['title']) || isset($fields['text'])) {
         // We do not need to save ID, title and text (content) as they are saved by WordPress itself.
         unset($fields['id'], $fields['title'], $fields['text']);
     }
     foreach ($fields as $field => $value) {
         $this->wp->updatePostMeta($object->getId(), $field, $value);
     }
     //
     //$this->addTemplate($object->getId(), $object->getActions());
     $this->wp->doAction('jigoshop\\service\\email\\save', $object);
 }
Beispiel #8
0
 /**
  * @param EntityInterface $object
  */
 private function recalculateTax(EntityInterface $object)
 {
     /** @var Order $order */
     $order = new Order(array());
     $order = $this->factory->fill($order, $object->getStateToSave());
     $object->setTaxDefinitions($order->getTaxDefinitions());
 }
Beispiel #9
0
 /**
  * Saves product to database.
  *
  * @param \Jigoshop\Entity\EntityInterface $object Product to save.
  *
  * @throws Exception
  */
 public function save(EntityInterface $object)
 {
     if (!$object instanceof \Jigoshop\Entity\Product) {
         throw new Exception('Trying to save not a product!');
     }
     // TODO: Support for transactions!
     $fields = $object->getStateToSave();
     if (isset($fields['id']) || isset($fields['name']) || isset($fields['description'])) {
         // We do not need to save ID, name and description (excerpt) as they are saved by WordPress itself.
         unset($fields['id'], $fields['name'], $fields['description']);
     }
     if (isset($fields['attributes'])) {
         $this->_removeAllProductAttributesExcept($object->getId(), array_map(function ($item) {
             /** @var $item Attribute */
             return $item->getId();
         }, $fields['attributes']));
         foreach ($fields['attributes'] as $attribute) {
             $this->_saveProductAttribute($object, $attribute);
         }
         unset($fields['attributes']);
     }
     if (isset($fields['attachments'])) {
         $this->_removeAllProductAttachments($object->getId());
         foreach ($fields['attachments'] as $attachment) {
             $this->_saveProductAttachment($object->getId(), $attachment);
         }
     }
     foreach ($fields as $field => $value) {
         $this->wp->updatePostMeta($object->getId(), $field, $value);
     }
     $this->wp->doAction('jigoshop\\service\\product\\save', $object);
 }