コード例 #1
0
 /**
  * Save bundle to the database
  *
  * @param Bundle $bundle
  *
  * @return Bundle           Return Bundle with ID and authorship details updated.
  */
 public function save(Bundle $bundle)
 {
     if (!$bundle->getAuthorship()->createdAt()) {
         $bundle->getAuthorship()->create(new DateTimeImmutable(), $this->_user->id);
     }
     $result = $this->_query->run("\n\t\t\tINSERT INTO\n\t\t\t\tdiscount_bundle\n\t\t\t\t(\n\t\t\t\t\t`name`,\n\t\t\t\t\tallow_codes,\n\t\t\t\t\tstart,\n\t\t\t\t\t`end`,\n\t\t\t\t\tcreated_at,\n\t\t\t\t\tcreated_by\n\t\t\t\t)\n\t\t\tVALUES\n\t\t\t\t(\n\t\t\t\t\t:name?s,\n\t\t\t\t\t:allowsCodes?b,\n\t\t\t\t\t:start?dn,\n\t\t\t\t\t:end?dn,\n\t\t\t\t\t:createdAt?d,\n\t\t\t\t\t:createdBy?i\n\t\t\t\t)\n\t\t", ['name' => $bundle->getName(), 'allowsCodes' => $bundle->allowsCodes(), 'start' => $bundle->getStart(), 'end' => $bundle->getEnd(), 'createdAt' => new \DateTime(), 'createdBy' => $this->_user->id]);
     $bundle->setID($result->id());
     $this->_bundleProductCreate->save($bundle);
     $this->_bundlePriceCreate->save($bundle);
     $this->_bundleImageCreate->save($bundle);
     return $bundle;
 }
コード例 #2
0
 /**
  * Create an instance of Bundle from data taken from a submitted Form\BundleForm instance
  *
  * @param array $data
  *
  * @return Bundle
  */
 public function build(array $data)
 {
     $this->_validateData($data);
     $bundle = new Bundle($this->_defaultCurrency);
     if (!empty($data[Form\BundleForm::ID])) {
         $bundle->setID($data[Form\BundleForm::ID]);
     }
     $bundle->setName($data[Form\BundleForm::NAME]);
     if (!empty($data[Form\BundleForm::START])) {
         $bundle->setStart($data[Form\BundleForm::START]);
     }
     if (!empty($data[Form\BundleForm::END])) {
         $bundle->setEnd($data[Form\BundleForm::END]);
     }
     $bundle->setAllowCodes(!empty($data[Form\BundleForm::CODES]));
     $this->_addProducts($bundle, $data);
     $this->_addPrices($bundle, $data);
     $this->_addImage($bundle, $data);
     return $bundle;
 }