$value) { if(in_array($key, $validKeys)) { $this->$key = $value; } } } /** * save * * Serialize options to database */ public function save() { update_option(self::CONFIG_OPTION, $this->getAsArray()); } /** * getAsArray * * Get all options as array * * @return array */ public function getAsArray() { return get_object_vars($this); } /** * getAccessKeyId * * @return boolean|string */ public function getAccessKeyId() { return $this->accessKeyId; } /** * setAccessKeyId * * @param string $key * @throws InvalidArgumentException */ public function setAccessKeyId($key) { if($key === NULL || empty($key)) { $this->accessKeyId = false; } elseif(!preg_match(self::ACCESS_KEY_PATTERN, $key)) { throw new InvalidArgumentException('Invalid value for accessKeyId'); } else { $this->accessKeyId = $key; } } /** * getSecretAccessKeyId * * @return boolean|string */ public function getSecretAccessKeyId() { return $this->secretAccessKeyId; } /** * setSecretAccessKeyId * * @param string $key * @throws InvalidArgumentException */ public function setSecretAccessKeyId($key) { if($key === NULL || empty($key)) { $this->secretAccessKeyId = false; } elseif(!preg_match(self::SECRET_ACCESS_KEY_PATTERN, $key)) { throw new InvalidArgumentException('Invalid value for secretAccessKeyId'); } else { $this->secretAccessKeyId = $key; } } /** * getMarketplace * * @return bool|AmzFulfillment_AmazonMarketplace */ public function getMarketplace() { if($this->marketplace === false) { return false; } else { return new AmzFulfillment_AmazonMarketplace($this->marketplace); } } /** * getMarketplaceCountryCode * * @return boolean|string */ public function getMarketplaceCountryCode() { return $this->marketplace; } /** * setMarketplace * * @param string $marketplace * @throws InvalidArgumentException */ public function setMarketplace($marketplace) { if($marketplace === NULL || empty($marketplace)) { $this->marketplace = false; } elseif(!preg_match(self::MARKETPLACE_PATTERN, $marketplace)) { throw new InvalidArgumentException('Invalid value for marketplace'); } else { $this->marketplace = $marketplace; } } /** * getMerchantId * * @return boolean|string */ public function getMerchantId() { return $this->merchantId; } /** * setMerchantId * * @param string $merchantId * @throws InvalidArgumentException */ public function setMerchantId($merchantId) { if($merchantId === NULL || empty($merchantId)) { $this->merchantId = false; } elseif(!preg_match(self::MERCHANT_ID_PATTERN, $merchantId)) { throw new InvalidArgumentException('Invalid value for merchantId'); } else { $this->merchantId = $merchantId; } } /** * getHold * * @return boolean */ public function getHold() { return (boolean) $this->hold; } /** * setHold * * @param boolean $hold */ public function setHold($hold) { $this->hold = (boolean) $hold; } /** * getSyncSkus * * @return string[] */ public function getSyncSkus() { return $this->syncSkus; } /** * setSyncSkus * * @param string[] $skus */ public function setSyncSkus($skus) { if(!is_array($skus)) { $this->syncSkus = array(); } else { $this->syncSkus = $skus; } } /** * isSyncSku * * @param string $sku * @return boolean true if sku is in array of selected skus */ public function isSyncSku($sku) { return in_array($sku, $this->syncSkus); } /** * getSchedulingInterval * * @return number seconds */ public function getSchedulingInterval() { return intval($this->schedulingInterval); } /** * setSchedulingInterval * * @param int $schedulingInterval seconds */ public function setSchedulingInterval($schedulingInterval) { if($schedulingInterval > self::SCHDULING_INTERVAL_MAX) { $this->schedulingInterval = self::SCHDULING_INTERVAL_MAX; } elseif ($schedulingInterval < self::SCHDULING_INTERVAL_MIN) { $this->schedulingInterval = self::SCHDULING_INTERVAL_MIN; } else { $this->schedulingInterval = intval($schedulingInterval); } } /** * getAutomation * * @return boolean */ public function getAutomation() { return (boolean) $this->automation; } /** * setAutomation * * @param boolean $automation */ public function setAutomation($automation) { $this->automation = (boolean) $automation; } /** * getLicenseKey * * @return boolean|string */ public function getLicenseKey() { return $this->licenseKey; } /** * setLicense * * @param string $key * @param int $expireDate */ public function setLicense($key, $expireDate) { if($key === NULL || empty($key) || $expireDate === NULL || empty($expireDate)) { $this->licenseKey = false; $this->licenseExpireDate = false; } else { $this->licenseKey = $key; $this->licenseExpireDate = $expireDate; } } /** * getLicenseOldKey * * @return boolean|string */ public function getLicenseOldKey() { return $this->licenseOldKey; } /** * setLicenseOldKey * * @param string $key */ public function setLicenseOldKey($key) { if($key === NULL || empty($key)) { $this->licenseOldKey = false; } else { $this->licenseOldKey = $key; } } /** * getLicenseExpireDate * * @return boolean|integer timestamp */ public function getLicenseExpireDate() { return $this->licenseExpireDate; } /** * hasAmazonCredentials * * @return boolean */ public function hasAmazonCredentials() { if($this->accessKeyId === false || $this->secretAccessKeyId === false || $this->marketplace === false || $this->merchantId === false) { return false; } else { return true; } } }