コード例 #1
0
ファイル: CouponService.php プロジェクト: jigoshop/Jigoshop2
 /**
  * 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);
 }
コード例 #2
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);
     }
 }
コード例 #3
0
ファイル: EmailService.php プロジェクト: jigoshop/Jigoshop2
 /**
  * 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);
 }
コード例 #4
0
ファイル: OrderService.php プロジェクト: jigoshop/Jigoshop2
 /**
  * @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());
 }
コード例 #5
0
ファイル: ProductService.php プロジェクト: jigoshop/Jigoshop2
 /**
  * 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);
 }