Пример #1
0
 public static function addFilesForProduct(array $files, StoreProduct $product)
 {
     self::removeFilesForProduct($product);
     //add new ones.
     if (!empty($files['dffID'])) {
         foreach ($files['dffID'] as $fileID) {
             if (!empty($fileID) && $fileID > 0) {
                 self::add($product->getProductID(), $fileID);
                 $fileObj = \File::getByID($fileID);
                 $fs = \FileSet::getByName("Digital Downloads");
                 $fs->addFileToSet($fileObj);
                 $fileObj->resetPermissions(1);
                 $pk = \Concrete\Core\Permission\Key\FileKey::getByHandle('view_file');
                 $pk->setPermissionObject($fileObj);
                 $pao = $pk->getPermissionAssignmentObject();
                 $groupEntity = \Concrete\Core\Permission\Access\Entity\GroupEntity::getOrCreate(\Group::getByID(GUEST_GROUP_ID));
                 $pa = $pk->getPermissionAccessObject();
                 if ($pa) {
                     $pa->removeListItem($groupEntity);
                     $pao->assignPermissionAccess($pa);
                 }
             }
         }
     }
 }
Пример #2
0
 public function add($data, $oID, $tax = 0, $taxIncluded = 0, $taxName = '')
 {
     $db = Database::get();
     $product = VividProduct::getByID($data['product']['pID']);
     $productName = $product->getProductName();
     $productPrice = $product->getActivePrice();
     $qty = $data['product']['qty'];
     if (!$product->pQtyUnlim) {
         $inStock = $product->getProductQty();
         $newStock = $inStock - $qty;
         $product->setProductQty($newStock);
     }
     $pID = $product->getProductID();
     $values = array($oID, $pID, $productName, $productPrice, $tax, $taxIncluded, $taxName, $qty);
     $db->Execute("INSERT INTO VividStoreOrderItems (oID,pID,oiProductName,oiPricePaid,oiTax,oiTaxIncluded,oiTaxName,oiQty) VALUES (?,?,?,?,?,?,?,?)", $values);
     $oiID = $db->lastInsertId();
     foreach ($data['productAttributes'] as $optionGroup => $selectedOption) {
         $optionGroupID = str_replace("pog", "", $optionGroup);
         $optionGroupName = VividProduct::getProductOptionGroupNameByID($optionGroupID);
         $optionValue = VividProduct::getProductOptionValueByID($selectedOption);
         $values = array($oiID, $optionGroupName, $optionValue);
         $db->Execute("INSERT INTO VividStoreOrderItemOptions (oiID,oioKey,oioValue) VALUES (?,?,?)", $values);
     }
     if ($product->hasDigitalDownload()) {
         $fileObjs = $product->getProductDownloadFileObjects();
         $fileObj = $fileObjs[0];
         $pk = \Concrete\Core\Permission\Key\FileKey::getByHandle('view_file');
         $pk->setPermissionObject($fileObj);
         $pao = $pk->getPermissionAssignmentObject();
         $u = new User();
         $uID = $u->getUserID();
         $ui = UserInfo::getByID($uID);
         $user = \Concrete\Core\Permission\Access\Entity\UserEntity::getOrCreate($ui);
         $pa = $pk->getPermissionAccessObject();
         if ($pa) {
             $pa->addListItem($user);
             $pao->assignPermissionAccess($pa);
         }
     }
 }
Пример #3
0
 public function save($data)
 {
     $db = Database::get();
     if ($data['pID']) {
         //if we know the pID, we're updating.
         $pID = $data['pID'];
         //update product details
         $vals = array($data['gID'], $data['pName'], $data['pDesc'], $data['pDetail'], $data['pPrice'], $data['pFeatured'], $data['pQty'], $data['pTaxable'], $data['pfID'], $data['pActive'], $data['pShippable'], $data['pWidth'], $data['pHeight'], $data['pLength'], $data['pWeight'], $data['pID']);
         $db->Execute('UPDATE VividStoreProducts SET gID=?,pName=?,pDesc=?,pDetail=?,pPrice=?,pFeatured=?,pQty=?,pTaxable=?,pfID=?,pActive=?,pShippable=?,pWidth=?,pHeight=?,pLength=?,pWeight=? WHERE pID = ?', $vals);
         //update additional images
         $db->Execute('DELETE FROM VividStoreProductImages WHERE pID = ?', $data['pID']);
         $count = count($data['pifID']);
         if ($count > 0) {
             for ($i = 0; $i < $count; $i++) {
                 $vals = array($data['pID'], $data['pifID'][$i], $data['piSort'][$i]);
                 $db->Execute("INSERT INTO VividStoreProductImages (pID,pifID,piSort) VALUES (?,?,?)", $vals);
             }
         }
         //update user groups
         $db->Execute('DELETE FROM VividStoreProductUserGroups WHERE pID = ?', $data['pID']);
         if (!empty($data['pUserGroups'])) {
             foreach ($data['pUserGroups'] as $gID) {
                 $vals = array($data['pID'], $gID);
                 $db->Execute("INSERT INTO VividStoreProductUserGroups (pID,gID) VALUES (?,?)", $vals);
             }
         }
         //update product groups
         $db->Execute('DELETE FROM VividStoreProductGroups WHERE pID = ?', $data['pID']);
         if (!empty($data['pProductGroups'])) {
             foreach ($data['pProductGroups'] as $gID) {
                 $vals = array($pID, $gID);
                 $db->Execute("INSERT INTO VividStoreProductGroups (pID,gID) VALUES (?,?)", $vals);
             }
         }
         //update option groups
         $db->Execute('DELETE FROM VividStoreProductOptionGroups WHERE pID = ?', $data['pID']);
         $db->Execute('DELETE FROM VividStoreProductOptionItems WHERE pID = ?', $data['pID']);
         $count = count($data['pogSort']);
         $ii = 0;
         //set counter for items
         if ($count > 0) {
             for ($i = 0; $i < $count; $i++) {
                 $vals = array($data['pID'], $data['pogName'][$i], $data['pogSort'][$i]);
                 $db->Execute("INSERT INTO VividStoreProductOptionGroups (pID,pogName,pogSort) VALUES (?,?,?)", $vals);
                 //add option items
                 $pogID = $db->lastInsertId();
                 $itemsInGroup = count($data['optGroup' . $i]);
                 if ($itemsInGroup > 0) {
                     for ($gi = 0; $gi < $itemsInGroup; $gi++, $ii++) {
                         $vals = array($data['pID'], $pogID, $data['poiName'][$ii], $data['poiSort'][$ii]);
                         $db->Execute("INSERT INTO VividStoreProductOptionItems (pID,pogID,poiName,poiSort) VALUES (?,?,?,?)", $vals);
                     }
                 }
             }
         }
     } else {
         //else, we don't know it, so we're adding
         $dt = Core::make('helper/date');
         $now = $dt->getLocalDateTime();
         //add product details
         $vals = array($data['gID'], $data['pName'], $data['pDesc'], $data['pDetail'], $data['pPrice'], $data['pFeatured'], $data['pQty'], $data['pTaxable'], $data['pfID'], $data['pActive'], $data['pShippable'], $data['pWidth'], $data['pHeight'], $data['pLength'], $data['pWeight'], $now);
         $db->Execute("INSERT INTO VividStoreProducts (gID,pName,pDesc,pDetail,pPrice,pFeatured,pQty,pTaxable,pfID,pActive,pShippable,pWidth,pHeight,pLength,pWeight,pDateAdded) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)", $vals);
         //add additional images
         $pID = $db->lastInsertId();
         $count = count($data['pifID']);
         if ($count > 0) {
             for ($i = 0; $i < $count; $i++) {
                 $vals = array($pID, $data['pifID'][$i], $data['piSort'][$i]);
                 $db->Execute("INSERT INTO VividStoreProductImages (pID,pifID,piSort) VALUES (?,?,?)", $vals);
             }
         }
         //insert user groups
         if (!empty($data['pUserGroups'])) {
             foreach ($data['pUserGroups'] as $gID) {
                 $vals = array($pID, $gID);
                 $db->Execute("INSERT INTO VividStoreProductUserGroups (pID,gID) VALUES (?,?)", $vals);
             }
         }
         //insert product groups
         if (!empty($data['pProductGroups'])) {
             foreach ($data['pProductGroups'] as $gID) {
                 $vals = array($pID, $gID);
                 $db->Execute("INSERT INTO VividStoreProductGroups (pID,gID) VALUES (?,?)", $vals);
             }
         }
         //add option groups
         $count = count($data['pogSort']);
         $ii = 0;
         //set counter for items
         if ($count > 0) {
             for ($i = 0; $i < $count; $i++) {
                 $vals = array($pID, $data['pogName'][$i], $data['pogSort'][$i]);
                 $db->Execute("INSERT INTO VividStoreProductOptionGroups (pID,pogName,pogSort) VALUES (?,?,?)", $vals);
                 //add option items
                 $pogID = $db->lastInsertId();
                 $itemsInGroup = count($data['optGroup' . $i]);
                 if ($itemsInGroup > 0) {
                     for ($gi = 0; $gi < $itemsInGroup; $gi++, $ii++) {
                         $vals = array($pID, $pogID, $data['poiName'][$ii], $data['poiSort'][$ii]);
                         $db->Execute("INSERT INTO VividStoreProductOptionItems (pID,pogID,poiName,poiSort) VALUES (?,?,?,?)", $vals);
                     }
                 }
             }
         }
         $product = Product::getByID($pID);
         $product->generatePage($data['selectPageTemplate']);
     }
     //save files
     $db->Execute("DELETE FROM VividStoreDigitalFiles WHERE pID=?", $pID);
     $u = User::getByUserID(1);
     $ui = \UserInfo::getByID($u->getUserID());
     if ($data['dffID']) {
         foreach ($data['dffID'] as $dffID) {
             if ($dffID) {
                 $db->Execute("INSERT INTO VividStoreDigitalFiles(dffID,pID) VALUES (?,?)", array($dffID, $pID));
                 $fileObj = File::getByID($dffID);
                 $fs = \FileSet::getByName("Digital Downloads");
                 $fs->addFileToSet($fileObj);
                 $fileObj->resetPermissions(1);
                 $pk = \Concrete\Core\Permission\Key\FileKey::getByHandle('view_file');
                 $pk->setPermissionObject($fileObj);
                 $pao = $pk->getPermissionAssignmentObject();
                 $groupEntity = \Concrete\Core\Permission\Access\Entity\GroupEntity::getOrCreate(\Group::getByID(GUEST_GROUP_ID));
                 $pa = $pk->getPermissionAccessObject();
                 if ($pa) {
                     $pa->removeListItem($groupEntity);
                     $pao->assignPermissionAccess($pa);
                 }
             }
         }
     }
     $db->Execute("DELETE FROM VividStoreProductLocations where pID = ?", array($pID));
     foreach ($data['cID'] as $cID) {
         if ($cID > 0) {
             $db->Execute("REPLACE INTO VividStoreProductLocations(pID,cID) VALUES (?,?)", array($pID, (int) $cID));
         }
     }
     $product = Product::getByID($pID);
     return $product;
 }
Пример #4
0
 private function assignFilePermissions()
 {
     foreach ($this->getOrderItems() as $orderItem) {
         $product = $orderItem->getProductObject();
         if ($product->hasDigitalDownload()) {
             $fileObjs = StoreProductFile::getFileObjectsForProduct($product);
             $fileObj = $fileObjs[0];
             $pk = \Concrete\Core\Permission\Key\FileKey::getByHandle('view_file');
             $pk->setPermissionObject($fileObj);
             $pao = $pk->getPermissionAssignmentObject();
             $u = new User();
             $uID = $u->getUserID();
             $ui = UserInfo::getByID($uID);
             $user = \Concrete\Core\Permission\Access\Entity\UserEntity::getOrCreate($ui);
             $pa = $pk->getPermissionAccessObject();
             if ($pa) {
                 $pa->addListItem($user);
                 $pao->assignPermissionAccess($pa);
             }
         }
     }
 }